<?php

//处理专题提交变量
function DoPostZtVar($add){
	if(empty($add[zttype])){
		$add[zttype]=".html";
	}
	if(empty($add[ztnum])){
		$add[ztnum]=25;
	}
	$add[zcid]=(int)$add['zcid'];
	$add[jstempid]=(int)$add['jstempid'];
	$add[intro]=addslashes(RepPhpAspJspcode($add[intro]));
	$add[ztpagekey]=addslashes(RepPhpAspJspcode($add[ztpagekey]));
	$add[ztnum]=(int)$add[ztnum];
	$add[listtempid]=(int)$add[listtempid];
	$add[newline]=(int)$add[newline];
	$add[newstrlen]=(int)$add[newstrlen];
	$add[newshowdate]=(int)$add[newshowdate];
	$add[hotline]=(int)$add[hotline];
	$add[hotstrlen]=(int)$add[hotstrlen];
	$add[hotshowdate]=(int)$add[hotshowdate];
	$add[goodline]=(int)$add[goodline];
	$add[goodshowdate]=(int)$add[goodshowdate];
	$add[goodstrlen]=(int)$add[goodstrlen];
	$add[classid]=(int)$add[classid];
	$add[hotplline]=(int)$add[hotplline];
	$add[hotplshowdate]=(int)$add[hotplshowdate];
	$add[hotplstrlen]=(int)$add[hotplstrlen];
	$add[firstline]=(int)$add[firstline];
	$add[firststrlen]=(int)$add[firststrlen];
	$add[firstshowdate]=(int)$add[firstshowdate];
	$add[islist]=(int)$add[islist];
	$add[maxnum]=(int)$add[maxnum];
	$add[showzt]=(int)$add[showzt];
	$add[classtempid]=(int)$add[classtempid];
	$add['myorder']=(int)$add['myorder'];
	$add[nrejs]=(int)$add[nrejs];
	//目录
	$add[ztpath]=$add['pripath'].$add['ztpath'];
	return $add;
}

//增加专题
function AddZt($add,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	$add[ztpath]=trim($add[ztpath]);
	if(!$add[ztname]||!$add[listtempid]||!$add[ztpath]){
		printerror("EmptyZt","");
	}
	CheckLevel($userid,$username,$classid,"zt");
	$add=DoPostZtVar($add);
	$createpath='../../'.$add[ztpath];
	//检测目录是否存在
	if(file_exists($createpath)){
		printerror("ReZtpath","");
	}
	CreateZtPath($add[ztpath]);//建立专题目录
	//取得表名
	$tabler=GetModTable(GetListtempMid($add[listtempid]));
	$tabler[tid]=(int)$tabler[tid];
	$sql=$empire->query("insert into {$dbtbpre}enewszt(ztname,ztnum,listtempid,onclick,ztpath,zttype,newline,newstrlen,newshowdate,zturl,hotline,hotstrlen,hotshowdate,goodline,goodshowdate,goodstrlen,classid,hotplline,hotplshowdate,hotplstrlen,firstline,firststrlen,firstshowdate,islist,maxnum,tid,tbname,reorderf,reorder,intro,ztimg,zcid,jstempid,showzt,ztpagekey,classtempid,myorder,nrejs) values('$add[ztname]',$add[ztnum],$add[listtempid],0,'$add[ztpath]','$add[zttype]',$add[newline],$add[newstrlen],$add[newshowdate],'$add[zturl]',$add[hotline],$add[hotstrlen],$add[hotshowdate],$add[goodline],$add[goodshowdate],$add[goodstrlen],$add[classid],$add[hotplline],$add[hotplshowdate],$add[hotplstrlen],$add[firstline],$add[firststrlen],$add[firstshowdate],$add[islist],$add[maxnum],$tabler[tid],'$tabler[tbname]','$add[reorderf]','$add[reorder]','$add[intro]','$add[ztimg]',$add[zcid],$add[jstempid],$add[showzt],'$add[ztpagekey]','$add[classtempid]',$add[myorder],$add[nrejs]);");
	$ztid=$empire->lastid();
	//生成页面
	if(!$add[islist]){
		NewsBq($ztid,GetClassTemp($add['classtempid']),3,1);
    }
	GetClass();//更新缓存
	if($sql){
		insert_dolog("ztid=".$ztid."<br>ztname=".$add[ztname]);//操作日志
		printerror("AddZtSuccess","AddZt.php?enews=AddZt");
	}
	else{
		printerror("DbError","");
	}
}

//修改专题
function EditZt($add,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	$add[ztid]=(int)$add[ztid];
	$add[ztpath]=trim($add[ztpath]);
	if(!$add[ztname]||!$add[listtempid]||!$add[ztpath]||!$add[ztid]){
		printerror("EmptyZt","");
	}
	CheckLevel($userid,$username,$classid,"zt");
	$add=DoPostZtVar($add);
	//改变目录
	if($add[oldztpath]<>$add[ztpath]){
		$createpath='../../'.$add[ztpath];
		if(file_exists($createpath)){
			printerror("ReZtpath","");
		}
		if($add['oldpripath']==$add['pripath']){
			$new="../../";
			@rename($new.$add[oldztpath],$new.$add[ztpath]);//改变目录名
		}
		else{
			CreateZtPath($add[ztpath]);//建立专题目录
		}
    }
	//取得表名
	$tabler=GetModTable(GetListtempMid($add[listtempid]));
	$tabler[tid]=(int)$tabler[tid];
	$sql=$empire->query("update {$dbtbpre}enewszt set ztname='$add[ztname]',ztnum=$add[ztnum],listtempid=$add[listtempid],ztpath='$add[ztpath]',zttype='$add[zttype]',newline=$add[newline],newstrlen=$add[newstrlen],newshowdate=$add[newshowdate],zturl='$add[zturl]',hotline=$add[hotline],hotstrlen=$add[hotstrlen],hotshowdate=$add[hotshowdate],goodline=$add[goodline],goodstrlen=$add[goodstrlen],goodshowdate=$add[goodshowdate],classid=$add[classid],hotplline=$add[hotplline],hotplshowdate=$add[hotplshowdate],hotplstrlen=$add[hotplstrlen],firstline=$add[firstline],firststrlen=$add[firststrlen],firstshowdate=$add[firstshowdate],islist=$add[islist],maxnum=$add[maxnum],tid=$tabler[tid],tbname='$tabler[tbname]',reorderf='$add[reorderf]',reorder='$add[reorder]',intro='$add[intro]',ztimg='$add[ztimg]',zcid=$add[zcid],jstempid=$add[jstempid],showzt=$add[showzt],ztpagekey='$add[ztpagekey]',classtempid='$add[classtempid]',myorder=$add[myorder],nrejs=$add[nrejs] where ztid='$add[ztid]'");
	GetClass();//更新缓存
	//生成页面
	if(!$add[islist]){
		NewsBq($add[ztid],GetClassTemp($add['classtempid']),3,1);
    }
	if($sql){
		insert_dolog("ztid=".$add[ztid]."<br>ztname=".$add[ztname]);//操作日志
		printerror("EditZtSuccess","ListZt.php");
	}
	else{
		printerror("DbError","");
	}
}

//删除专题
function DelZt($ztid,$userid,$username){
	global $empire,$dbtbpre;
	$ztid=(int)$ztid;
	if(!$ztid){
		printerror("NotDelZtid","");
	}
	CheckLevel($userid,$username,$classid,"zt");
	$r=$empire->fetch1("select * from {$dbtbpre}enewszt where ztid='$ztid'");
	if(empty($r[ztid])){
		printerror("NotDelZtid","history.go(-1)");
	}
	//删除专题
	$sql=$empire->query("delete from {$dbtbpre}enewszt where ztid='$ztid'");
	$delpath="../../".$r[ztpath];
	$del=DelPath($delpath);
	//改变信息专题值
	$nsql=$empire->query("select id,ztid from {$dbtbpre}ecms_".$r[tbname]." where ztid like '%|".$ztid."|%'");
	while($nr=$empire->fetch($nsql))
	{
		$newztid=str_replace("|".$ztid."|","|",$nr[ztid]);
		$usql=$empire->query("update {$dbtbpre}ecms_".$r[tbname]." set ztid='$newztid' where id='$nr[id]'");
    }
	GetClass();//更新缓存
	if($sql){
		insert_dolog("ztid=".$ztid."<br>ztname=".$r[ztname]);//操作日志
		printerror("DelZtSuccess","ListZt.php");
	}
	else{
		printerror("DbError","");
	}
}

//检测目录已存在
function CheckPath($classpath){
	global $fun_r;
	if(empty($classpath)){
		echo $fun_r['EmptyPath'];
	}
	else{
		if(file_exists("../../".$classpath)){
			echo $fun_r['RePath'];
		}
		else{
			echo $fun_r['PathNot'];
		}
	}
	exit();
}

//组合不生成的栏目信息
function TogNotReClass($changecache=0){
	global $empire,$dbtbpre;
	$sql=$empire->query("select classid,nreclass,nreinfo,nrejs,nottobq from {$dbtbpre}enewsclass where nreclass=1 or nreinfo=1 or nrejs=1 or nottobq=1");
	$nreclass=',';
	$nreinfo=',';
	$nrejs=',';
	$nottobq=',';
	while($r=$empire->fetch($sql))
	{
		if($r['nreclass']==1)
		{
			$nreclass.=$r['classid'].',';
		}
		if($r['nreinfo']==1)
		{
			$nreinfo.=$r['classid'].',';
		}
		if($r['nrejs']==1)
		{
			$nrejs.=$r['classid'].',';
		}
		if($r['nottobq']==1)
		{
			$nottobq.=$r['classid'].',';
		}
	}
	$empire->query("update {$dbtbpre}enewspublic set nreclass='$nreclass',nreinfo='$nreinfo',nrejs='$nrejs',nottobq='$nottobq' limit 1");
	if($changecache==1)
	{
		GetConfig();
	}
}

//处理栏目提交变量
function DoPostClassVar($add){
	if(empty($add[classtype])){
		$add[classtype]=".html";
	}
	$add[intro]=addslashes(RepPhpAspJspcode($add[intro]));
	$add[classpagekey]=addslashes(RepPhpAspJspcode($add[classpagekey]));
	//过滤字符
	$add[listorderf]=RepPostVar($add[listorderf]);
	$add[listorder]=RepPostVar($add[listorder]);
	$add[reorderf]=RepPostVar($add[reorderf]);
	$add[reorder]=RepPostVar($add[reorder]);
	//处理变量
	$add[jstempid]=(int)$add['jstempid'];
	$add[bclassid]=(int)$add[bclassid];
	$add[link_num]=(int)$add[link_num];
	if(empty($add[link_num])){
		$add[link_num]=10;
	}
	$add[newstempid]=(int)$add[newstempid];
	$add[islast]=(int)$add[islast];
	$add[filename]=(int)$add[filename];
	$add[openpl]=(int)$add[openpl];
	$add[openadd]=(int)$add[openadd];
	$add[newline]=(int)$add[newline];
	$add[newstrlen]=(int)$add[newstrlen];
	$add[newshowdate]=(int)$add[newshowdate];
	$add[hotline]=(int)$add[hotline];
	$add[hotstrlen]=(int)$add[hotstrlen];
	$add[hotshowdate]=(int)$add[hotshowdate];
	$add[goodline]=(int)$add[goodline];
	$add[goodstrlen]=(int)$add[goodstrlen];
	$add[goodshowdate]=(int)$add[goodshowdate];
	$add[groupid]=(int)$add[groupid];
	$add[hotplline]=(int)$add[hotplline];
	$add[hotplshowdate]=(int)$add[hotplshowdate];
	$add[hotplstrlen]=(int)$add[hotplstrlen];
	$add[modid]=(int)$add[modid];
	$add[checked]=(int)$add[checked];
	$add[docheckuser]=(int)$add[docheckuser];
	$add[firstline]=(int)$add[firstline];
	$add[firststrlen]=(int)$add[firststrlen];
	$add[firstshowdate]=(int)$add[firstshowdate];
	$add[islist]=(int)$add[islist];
	$add[searchtempid]=(int)$add[searchtempid];
	$add[checkpl]=(int)$add[checkpl];
	$add[down_num]=(int)$add[down_num];
	if(empty($add[down_num])){
		$add[down_num]=1;
	}
	$add[online_num]=(int)$add[online_num];
	if(empty($add[online_num])){
		$add[online_num]=1;
	}
	$add[addinfofen]=(int)$add[addinfofen];
	$add[listdt]=(int)$add[listdt];
	$add[showdt]=(int)$add[showdt];
	$add[maxnum]=(int)$add[maxnum];
	$add[showclass]=(int)$add[showclass];
	$add[checkqadd]=(int)$add[checkqadd];
	$add[qaddlist]=(int)$add[qaddlist];
	$add[qaddgroupid]=(int)$add[qaddgroupid];
	$add[qaddshowkey]=(int)$add[qaddshowkey];
	$add[adminqinfo]=(int)$add[adminqinfo];
	$add[doctime]=(int)$add[doctime];
	$add[nreclass]=(int)$add[nreclass];
	$add[nreinfo]=(int)$add[nreinfo];
	$add[nrejs]=(int)$add[nrejs];
	$add[nottobq]=(int)$add[nottobq];
	$add[lencord]=(int)$add[lencord];
	$add[listtempid]=(int)$add[listtempid];
	$add[dtlisttempid]=(int)$add[dtlisttempid];
	$add[classtempid]=(int)$add[classtempid];
	if(empty($add[bname])){
		$add[bname]=$add[classname];
	}
	$add[myorder]=(int)$add[myorder];
	if($add[infopath]==0)
	{
		$add[ipath]='';
	}
	$add[addreinfo]=(int)$add[addreinfo];
	$add[haddlist]=(int)$add[haddlist];
	$add[sametitle]=(int)$add[sametitle];
	$add[definfovoteid]=(int)$add[definfovoteid];
	$add[qeditchecked]=(int)$add[qeditchecked];
	$add[wapstyleid]=(int)$add[wapstyleid];
	return $add;
}

//增加外部栏目
function AddWbClass($add,$userid,$username){
	global $empire,$dbtbpre;
	//操作权限
	CheckLevel($userid,$username,$classid,"class");
	$add=DoPostClassVar($add);
	if(!$add[classname]||!$add[wburl])
	{
		printerror("EmptyWbClass","");
	}
	$add[islast]=0;
	//取得表名
	$tabler=GetModTable($add[modid]);
	$tabler[tid]=(int)$tabler[tid];
	if(empty($add[bclassid]))//主栏目
	{
		$sonclass="";
		$featherclass="";
	}
	else//中级栏目
	{
		//取得上一级父栏目
		$r=$empire->fetch1("select featherclass,islast,wburl from {$dbtbpre}enewsclass where classid='$add[bclassid]'");
		if($r[islast])//是否终极栏目
		{
			printerror("BclassNotLast","");
		}
		if($r[wburl])
		{
			printerror("BclassNotWb","");
		}
		if(empty($r[featherclass]))
		{
			$r[featherclass]="|";
		}
		$featherclass=$r[featherclass].$add[bclassid]."|";
		$sonclass="";
	}
	$sql=$empire->query("insert into {$dbtbpre}enewsclass(bclassid,classname,is_zt,sonclass,lencord,link_num,newstempid,onclick,listtempid,featherclass,islast,classpath,classtype,newspath,filename,filetype,openpl,openadd,newline,newstrlen,newshowdate,hotline,hotstrlen,hotshowdate,goodline,goodstrlen,goodshowdate,classurl,groupid,myorder,filename_qz,hotplline,hotplshowdate,hotplstrlen,modid,checked,docheckuser,checkuser,firstline,firststrlen,firstshowdate,bname,islist,searchtempid,tid,tbname,maxnum,checkpl,down_num,online_num,listorderf,listorder,reorderf,reorder,intro,classimg,jstempid,addinfofen,listdt,showclass,showdt,checkqadd,qaddlist,qaddgroupid,qaddshowkey,adminqinfo,doctime,classpagekey,dtlisttempid,classtempid,nreclass,nreinfo,nrejs,nottobq,ipath,addreinfo,haddlist,sametitle,definfovoteid,wburl,qeditchecked,wapstyleid) values($add[bclassid],'$add[classname]',0,'$sonclass',$add[lencord],$add[link_num],$add[newstempid],0,$add[listtempid],'$featherclass',$add[islast],'$classpath','$add[classtype]','$add[newspath]',$add[filename],'$add[filetype]',$add[openpl],$add[openadd],$add[newline],$add[newstrlen],$add[newshowdate],$add[hotline],$add[hotstrlen],$add[hotshowdate],$add[goodline],$add[goodstrlen],$add[goodshowdate],'$add[classurl]',$add[groupid],$add[myorder],'$add[filename_qz]',$add[hotplline],$add[hotplshowdate],$add[hotplstrlen],$add[modid],$add[checked],$add[docheckuser],'$add[checkuser]',$add[firstline],$add[firststrlen],$add[firstshowdate],'$add[bname]',$add[islist],$add[searchtempid],$tabler[tid],'$tabler[tbname]',$add[maxnum],$add[checkpl],$add[down_num],$add[online_num],'$add[listorderf]','$add[listorder]','$add[reorderf]','$add[reorder]','$add[intro]','$add[classimg]',$add[jstempid],$add[addinfofen],$add[listdt],$add[showclass],$add[showdt],$add[checkqadd],$add[qaddlist],$add[qaddgroupid],$add[qaddshowkey],$add[adminqinfo],$add[doctime],'$add[classpagekey]','$add[dtlisttempid]','$add[classtempid]',$add[nreclass],$add[nreinfo],$add[nrejs],$add[nottobq],'$add[ipath]',$add[addreinfo],$add[haddlist],$add[sametitle],$add[definfovoteid],'$add[wburl]',$add[qeditchecked],$add[wapstyleid]);");
	$lastid=$empire->lastid();
	GetClass();
	DelListEnews();//删除缓存文件
	if($sql)
	{
		insert_dolog("classid=".$lastid."<br>classname=".$add[classname]);//操作日志
		printerror("AddClassSuccess","AddClass.php?enews=AddClass&from=$add[from]");
	}
	else
	{
		printerror("DbError","");
	}
}

//增加栏目
function AddClass($add,$userid,$username){
	global $empire,$dbtbpre;
	//增加外部栏目
	if($add[ecmsclasstype])
	{
		AddWbClass($add,$userid,$username);
	}
	$add[classpath]=trim($add[classpath]);
	if(!$add[classname]||!$add[classpath]||!$add[modid])
	{
		printerror("EmptyClass","");
	}
	if($add[islast]&&(!$add[newstempid]||!$add[listtempid]))
	{
		printerror("LastMustChange","");
	}
	//操作权限
	CheckLevel($userid,$username,$classid,"class");
	$add=DoPostClassVar($add);
	//目录已存在
	if(strchr($add[classpath],".")||strchr($add[classpath],"/")||strchr($add[classpath],"\\"))
	{
		printerror("badpath","");
	}
	$classpath=$add[pripath].$add[classpath];
	if(file_exists("../../".$classpath))
	{
		printerror("ReClasspath","");
	}
	//取得表名
	$tabler=GetModTable($add[modid]);
	$tabler[tid]=(int)$tabler[tid];
	//增加大栏目
	if(!$add[islast])
	{
		if(empty($add[bclassid]))//主栏目
		{
			$sonclass="";
			$featherclass="";
	    }
		else//中级栏目
		{
			//取得上一级父栏目
			$r=$empire->fetch1("select featherclass,islast,wburl from {$dbtbpre}enewsclass where classid='$add[bclassid]'");
			if($r[islast])//是否终极栏目
			{
				printerror("BclassNotLast","");
			}
			if($r[wburl])
			{
				printerror("BclassNotWb","");
			}
			if(empty($r[featherclass]))
			{
				$r[featherclass]="|";
			}
			$featherclass=$r[featherclass].$add[bclassid]."|";
			$sonclass="";
	    }
		//建立目录
		CreateClassPath($classpath);
		$sql=$empire->query("insert into {$dbtbpre}enewsclass(bclassid,classname,is_zt,sonclass,lencord,link_num,newstempid,onclick,listtempid,featherclass,islast,classpath,classtype,newspath,filename,filetype,openpl,openadd,newline,newstrlen,newshowdate,hotline,hotstrlen,hotshowdate,goodline,goodstrlen,goodshowdate,classurl,groupid,myorder,filename_qz,hotplline,hotplshowdate,hotplstrlen,modid,checked,docheckuser,checkuser,firstline,firststrlen,firstshowdate,bname,islist,searchtempid,tid,tbname,maxnum,checkpl,down_num,online_num,listorderf,listorder,reorderf,reorder,intro,classimg,jstempid,addinfofen,listdt,showclass,showdt,checkqadd,qaddlist,qaddgroupid,qaddshowkey,adminqinfo,doctime,classpagekey,dtlisttempid,classtempid,nreclass,nreinfo,nrejs,nottobq,ipath,addreinfo,haddlist,sametitle,definfovoteid,wburl,qeditchecked,wapstyleid) values($add[bclassid],'$add[classname]',0,'$sonclass',$add[lencord],$add[link_num],$add[newstempid],0,$add[listtempid],'$featherclass',$add[islast],'$classpath','$add[classtype]','$add[newspath]',$add[filename],'$add[filetype]',$add[openpl],$add[openadd],$add[newline],$add[newstrlen],$add[newshowdate],$add[hotline],$add[hotstrlen],$add[hotshowdate],$add[goodline],$add[goodstrlen],$add[goodshowdate],'$add[classurl]',$add[groupid],$add[myorder],'$add[filename_qz]',$add[hotplline],$add[hotplshowdate],$add[hotplstrlen],$add[modid],$add[checked],$add[docheckuser],'$add[checkuser]',$add[firstline],$add[firststrlen],$add[firstshowdate],'$add[bname]',$add[islist],$add[searchtempid],$tabler[tid],'$tabler[tbname]',$add[maxnum],$add[checkpl],$add[down_num],$add[online_num],'$add[listorderf]','$add[listorder]','$add[reorderf]','$add[reorder]','$add[intro]','$add[classimg]',$add[jstempid],$add[addinfofen],$add[listdt],$add[showclass],$add[showdt],$add[checkqadd],$add[qaddlist],$add[qaddgroupid],$add[qaddshowkey],$add[adminqinfo],$add[doctime],'$add[classpagekey]','$add[dtlisttempid]','$add[classtempid]',$add[nreclass],$add[nreinfo],$add[nrejs],$add[nottobq],'$add[ipath]',$add[addreinfo],$add[haddlist],$add[sametitle],$add[definfovoteid],'',$add[qeditchecked],$add[wapstyleid]);");
		$lastid=$empire->lastid();
		TogNotReClass(1);
		GetClass();
		if(!$add[islist]){
			NewsBq($lastid,GetClassTemp($add['classtempid']),0,1);
		}
		DelListEnews();//删除缓存文件
		GetSearch($add[modid]);//更新缓存
		if($sql){
			insert_dolog("classid=".$lastid."<br>classname=".$add[classname]);//操作日志
			printerror("AddClassSuccess","AddClass.php?enews=AddClass&from=$add[from]");
		}
		else{
			printerror("DbError","");
		}
    }
	//增加终级栏目
	else
	{
		//文件前缀
		$add[filename_qz]=RepFilenameQz($add[filename_qz]);
		if(empty($add[bclassid]))//主类别为终级栏目时
		{
			$sonclass="";
			$featherclass="";
	    }
		else//子栏目
		{
			//取得上一级父栏目
			$r=$empire->fetch1("select featherclass,islast,wburl from {$dbtbpre}enewsclass where classid='$add[bclassid]'");
			//是否终极类别
			if($r[islast])
			{
				printerror("BclassNotLast","");
			}
			if($r[wburl])
			{
				printerror("BclassNotWb","");
			}
			if(empty($r[featherclass])){
				$r[featherclass]="|";
			}
			$featherclass=$r[featherclass].$add[bclassid]."|";
			$sonclass="";
		}
		//建立栏目目录
		CreateClassPath($classpath);
		$sql=$empire->query("insert into {$dbtbpre}enewsclass(bclassid,classname,sonclass,is_zt,lencord,link_num,newstempid,onclick,listtempid,featherclass,islast,classpath,classtype,newspath,filename,filetype,openpl,openadd,newline,newstrlen,newshowdate,hotline,hotstrlen,hotshowdate,goodline,goodstrlen,goodshowdate,classurl,groupid,myorder,filename_qz,hotplline,hotplshowdate,hotplstrlen,modid,checked,docheckuser,checkuser,firstline,firststrlen,firstshowdate,bname,islist,searchtempid,tid,tbname,maxnum,checkpl,down_num,online_num,listorderf,listorder,reorderf,reorder,intro,classimg,jstempid,addinfofen,listdt,showclass,showdt,checkqadd,qaddlist,qaddgroupid,qaddshowkey,adminqinfo,doctime,classpagekey,dtlisttempid,classtempid,nreclass,nreinfo,nrejs,nottobq,ipath,addreinfo,haddlist,sametitle,definfovoteid,wburl,qeditchecked,wapstyleid) values($add[bclassid],'$add[classname]','$sonclass',0,$add[lencord],$add[link_num],$add[newstempid],0,$add[listtempid],'$featherclass',$add[islast],'$classpath','$add[classtype]','$add[newspath]',$add[filename],'$add[filetype]',$add[openpl],$add[openadd],$add[newline],$add[newstrlen],$add[newshowdate],$add[hotline],$add[hotstrlen],$add[hotshowdate],$add[goodline],$add[goodstrlen],$add[goodshowdate],'$add[classurl]',$add[groupid],$add[myorder],'$add[filename_qz]',$add[hotplline],$add[hotplshowdate],$add[hotplstrlen],$add[modid],$add[checked],$add[docheckuser],'$add[checkuser]',$add[firstline],$add[firststrlen],$add[firstshowdate],'$add[bname]',$add[islist],$add[searchtempid],$tabler[tid],'$tabler[tbname]',$add[maxnum],$add[checkpl],$add[down_num],$add[online_num],'$add[listorderf]','$add[listorder]','$add[reorderf]','$add[reorder]','$add[intro]','$add[classimg]',$add[jstempid],$add[addinfofen],$add[listdt],$add[showclass],$add[showdt],$add[checkqadd],$add[qaddlist],$add[qaddgroupid],$add[qaddshowkey],$add[adminqinfo],$add[doctime],'$add[classpagekey]','$add[dtlisttempid]','$add[classtempid]',$add[nreclass],$add[nreinfo],$add[nrejs],$add[nottobq],'$add[ipath]',$add[addreinfo],$add[haddlist],$add[sametitle],$add[definfovoteid],'',$add[qeditchecked],$add[wapstyleid]);");
		$lastid=$empire->lastid();
		//修改父栏目的子栏目
		if($add[bclassid])
		{
			$b_r=$empire->fetch1("select sonclass,featherclass from {$dbtbpre}enewsclass where classid='$add[bclassid]'");
			if(empty($b_r[sonclass]))
			{
				$b_r[sonclass]="|";
			}
			$new_sonclass=$b_r[sonclass].$lastid."|";
			$update=$empire->query("update {$dbtbpre}enewsclass set sonclass='$new_sonclass' where classid='$add[bclassid]'");
			//更改父类别的父栏目的子栏目
			$where=ReturnClass($b_r[featherclass]);
			if(empty($where)){
				$where="classid=0";
			}
			$bsql=$empire->query("select sonclass,classid from {$dbtbpre}enewsclass where ".$where);
			while($br=$empire->fetch($bsql))
			{
				if(empty($br[sonclass]))
				{
					$br[sonclass]="|";
				}
				$new_sonclass=$br[sonclass].$lastid."|";
				$update=$empire->query("update {$dbtbpre}enewsclass set sonclass='$new_sonclass' where classid='$br[classid]'");
            }
	    }
		DelListEnews();//删除缓存文件
		TogNotReClass(1);
		GetClass();
		GetSearch($add[modid]);//更新缓存
		if($sql){
			insert_dolog("classid=".$lastid."<br>classname=".$add[classname]);//操作日志
			printerror("AddLastClassSuccess","AddClass.php?enews=AddClass&from=$add[from]");
		}
		else{
			printerror("DbError","history.go(-1)");
		}
    }
}

//绑定域名应用于子栏目
function UpdateSmallClassDomain($classid,$classurl,$classpath){
	global $empire,$dbtbpre;
	if(empty($classurl)){
		$query="update {$dbtbpre}enewsclass set classurl='' where featherclass like '%|".$classid."|%'";
    }
	else{
		$query="update {$dbtbpre}enewsclass set classurl=CONCAT('".$classurl."',SUBSTRING(classpath,LENGTH('".$classpath."')+1)) where featherclass like '%|".$classid."|%'";
    }
	$sql=$empire->query($query);
}

//栏目目录修改
function AlterClassPath($classid,$islast,$oldclasspath,$classpath){
	global $empire,$dbtbpre;
	//更新目录名
	if($oldclassname!=$classpath)
	{
		@rename("../../".$oldclasspath,"../../".$classpath);
		@rename("../../d/file/".$oldclasspath,"../../d/file/".$classpath);
		if(empty($islast))
		{
			$sql=$empire->query("update {$dbtbpre}enewsclass set classpath=REPLACE(classpath,'".$oldclasspath."/','".$classpath."/') where featherclass like '%|".$classid."|%'");
		}
		DelListEnews();
	}
}

//修改外部栏目
function EditWbClass($add,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	//操作权限
	CheckLevel($userid,$username,$classid,"class");
	$add=DoPostClassVar($add);
	$add[classid]=(int)$add[classid];
	if(!$add[classname]||!$add[classid]||!$add[wburl])
	{
		printerror("EmptyWbClass","");
	}
	$add[islast]=0;
	//取得表名
	$tabler=GetModTable($add[modid]);
	$tabler[tid]=(int)$tabler[tid];
	//改变大栏目
	if($add[bclassid]<>$add[oldbclassid])
	{
		//转到主栏目
		if(empty($add[bclassid]))
		{
			$sonclass="";
			$featherclass="";
		}
		//转到中级栏目
		else
		{
			//大栏目跟原栏目相同
			if($add[classid]==$add[bclassid])
			{
				printerror("BclassIsself","");
			}
			//取得现在大栏目的值
	 		$b=$empire->fetch1("select featherclass,sonclass,islast,wburl from {$dbtbpre}enewsclass where classid='$add[bclassid]'");
			//检测大栏目是否为终级栏目
			if($b[islast])
			{
				printerror("BclassNotLast","");
			}
			if($b[wburl])
			{
				printerror("BclassNotWb","");
			}
			//是否非法父栏目
			if($b[featherclass])
			{
				$c_nb_r=explode("|".$add[classid]."|",$b[featherclass]);
				if(count($c_nb_r)<>1)
				{
					printerror("BclassIssmall","");
				}
			}
			if(empty($b[featherclass]))
			{
				$b[featherclass]="|";
			}
			$featherclass=$b[featherclass].$add[bclassid]."|";
		}
		$change=",bclassid=$add[bclassid],featherclass='$featherclass'";
	}
	//修改数据库资料
	$sql=$empire->query("update {$dbtbpre}enewsclass set classname='$add[classname]',classpath='$classpath',classtype='$add[classtype]',newline=$add[newline],newstrlen=$add[newstrlen],newshowdate=$add[newshowdate],hotline=$add[hotline],hotstrlen=$add[hotstrlen],hotshowdate=$add[hotshowdate],goodline=$add[goodline],goodstrlen=$add[goodstrlen],goodshowdate=$add[goodshowdate],classurl='$add[classurl]',groupid=$add[groupid],myorder=$add[myorder],filename_qz='$add[filename_qz]',hotplline=$add[hotplline],hotplshowdate=$add[hotplshowdate],hotplstrlen=$add[hotplstrlen],modid=$add[modid],checked=$add[checked],docheckuser=$add[docheckuser],checkuser='$add[checkuser]',firstline=$add[firstline],firststrlen=$add[firststrlen],firstshowdate=$add[firstshowdate],bname='$add[bname]',islist=$add[islist],listtempid=$add[listtempid],lencord=$add[lencord],searchtempid=$add[searchtempid],tid=$tabler[tid],tbname='$tabler[tbname]',maxnum=$add[maxnum],checkpl=$add[checkpl],down_num=$add[down_num],online_num=$add[online_num],listorderf='$add[listorderf]',listorder='$add[listorder]',reorderf='$add[reorderf]',reorder='$add[reorder]',intro='$add[intro]',classimg='$add[classimg]',jstempid=$add[jstempid],listdt=$add[listdt],showclass=$add[showclass],showdt=$add[showdt],qaddgroupid=$add[qaddgroupid],qaddshowkey=$add[qaddshowkey],adminqinfo=$add[adminqinfo],doctime=$add[doctime],classpagekey='$add[classpagekey]',dtlisttempid='$add[dtlisttempid]',classtempid='$add[classtempid]',nreclass=$add[nreclass],nreinfo=$add[nreinfo],nrejs=$add[nrejs],nottobq=$add[nottobq],ipath='$add[ipath]',addreinfo=$add[addreinfo],haddlist=$add[haddlist],sametitle=$add[sametitle],definfovoteid=$add[definfovoteid],wburl='$add[wburl]',qeditchecked=$add[qeditchecked],openadd=$add[openadd],wapstyleid='$add[wapstyleid]'".$change." where classid='$add[classid]'");
	GetClass();
	//删除缓存文件
	if($add[oldclassname]<>$add[classname]||$add[bclassid]<>$add[oldbclassid])
	{
		DelListEnews();
    }
	//来源
	if($add['from'])
	{
		$returnurl="ListPageClass.php";
	}
	else
	{
		$returnurl="ListClass.php";
	}
	if($sql)
	{
		insert_dolog("classid=".$add[classid]."<br>classname=".$add[classname]);//操作日志
		printerror("EditClassSuccess",$returnurl);
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//修改栏目
function EditClass($add,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	//修改外部栏目
	if($add[ecmsclasstype])
	{
		EditWbClass($add,$userid,$username);
	}
	$add[classid]=(int)$add[classid];
	$add[classpath]=trim($add[classpath]);
	$checkclasspath=$add['classpath'];
	if($add['oldclasspath']<>$add['pripath'].$add['oldcpath'])//更换父栏目
	{
		$add[classpath]=$add['oldcpath'];
	}
	if(!$add[classname]||!$add[classpath]||!$add[modid]||!$add[classid]){
		printerror("EmptyClass","");
	}
	if($add[islast]&&(!$add[newstempid]||!$add[listtempid])){
		printerror("LastMustChange","");
	}
	//操作权限
	CheckLevel($userid,$username,$classid,"class");
	$add=DoPostClassVar($add);
	//改变目录
	$classpath=$add[pripath].$add[classpath];
	if($add[oldclasspath]<>$classpath&&$checkclasspath==$add['oldcpath']){
		if(file_exists("../../".$classpath)){//检测目录是否存在
			printerror("ReClasspath","");
		}
    }
	//取得表名
	$tabler=GetModTable($add[modid]);
	$tabler[tid]=(int)$tabler[tid];
	//修改大栏目
	if(!$add[islast]){
		//改变大栏目
		if($add[bclassid]<>$add[oldbclassid]){
			//转到主栏目
			if(empty($add[bclassid])){
				$sonclass="";
				$featherclass="";
				//取得本栏目的子栏目
				$r=$empire->fetch1("select sonclass,featherclass,classpath from {$dbtbpre}enewsclass where classid='$add[classid]'");
				//改变父栏目的子栏目
				$where=ReturnClass($r[featherclass]);
				if(empty($where)){
					$where="classid=0";
				}
				$osql=$empire->query("select sonclass,classid from {$dbtbpre}enewsclass where ".$where);
				while($o=$empire->fetch($osql)){
					$newsonclass=str_replace($r[sonclass],"|",$o[sonclass]);
					$uosql=$empire->query("update {$dbtbpre}enewsclass set sonclass='$newsonclass' where classid='$o[classid]'");
				}
				//修改子栏目的父栏目
				$osql=$empire->query("select featherclass,classid,classpath from {$dbtbpre}enewsclass where featherclass like '%|".$add[classid]."%|'");
				while($o=$empire->fetch($osql)){
					$newclasspath=str_replace($r[classpath]."/",$classpath."/",$o[classpath]);
					$newfeatherclass=str_replace($r[featherclass],"|",$o[featherclass]);
					$uosql=$empire->query("update {$dbtbpre}enewsclass set featherclass='$newfeatherclass',classpath='$newclasspath' where classid='$o[classid]'");
				}
			}
			//转到中级栏目
			else
			{
				//大栏目跟原栏目相同
				if($add[classid]==$add[bclassid]){
				  printerror("BclassIsself","");
				}
				//取得现在大栏目的值
	 			$b=$empire->fetch1("select featherclass,sonclass,islast,wburl from {$dbtbpre}enewsclass where classid='$add[bclassid]'");
				//检测大栏目是否为终级栏目
				if($b[islast])
				{
					printerror("BclassNotLast","");
				}
				if($b[wburl])
				{
					printerror("BclassNotWb","");
				}
				//是否非法父栏目
				if($b[featherclass]){
					$c_nb_r=explode("|".$add[classid]."|",$b[featherclass]);
					if(count($c_nb_r)<>1){
						printerror("BclassIssmall","");
					}
				}
				if(empty($b[featherclass])){
					$b[featherclass]="|";
				}
				$featherclass=$b[featherclass].$add[bclassid]."|";
				//取得现在栏目本身的值
				$o=$empire->fetch1("select featherclass,sonclass,classpath from {$dbtbpre}enewsclass where classid='$add[classid]'");
				//修改子栏目的父栏目
				$osql=$empire->query("select featherclass,classid,classpath from {$dbtbpre}enewsclass where featherclass like '%|".$add[classid]."|%'");
				while($or=$empire->fetch($osql)){
					$newclasspath=str_replace($o[classpath]."/",$classpath."/",$or[classpath]);
					if(empty($o[featherclass])){
						$newfeatherclass=$b[featherclass].$add[bclassid].$or[featherclass];
					}
					else{
						$newfeatherclass=str_replace($o[featherclass],$featherclass,$or[featherclass]);
					}
					$uosql=$empire->query("update {$dbtbpre}enewsclass set featherclass='$newfeatherclass',classpath='$newclasspath' where classid='$or[classid]'");
				}
				//改变旧大栏目的所有子栏目
				$owhere=ReturnClass($o[featherclass]);
				if(empty($owhere)){
					$owhere="classid=0";
				}
				$oosql=$empire->query("select sonclass,classid from {$dbtbpre}enewsclass where ".$owhere);
				while($oo=$empire->fetch($oosql)){
					$newsonclass=str_replace($o[sonclass],"|",$oo[sonclass]);
					$usql=$empire->query("update {$dbtbpre}enewsclass set sonclass='$newsonclass' where classid='$oo[classid]'");
				}
				//改变新大栏目的子栏目
				$where=ReturnClass($featherclass);
				if(empty($where)){
					$where="classid=0";
				}
				$nbsql=$empire->query("select sonclass,classid from {$dbtbpre}enewsclass where ".$where);
				while($nb=$empire->fetch($nbsql)){
					if(empty($nb[sonclass]))
					{$nb[sonclass]="|";}
					$newsonclass=$nb[sonclass].substr($o[sonclass],1);
					$usql=$empire->query("update {$dbtbpre}enewsclass set sonclass='$newsonclass' where classid='$nb[classid]'");
				}
			}
			$change=",bclassid=$add[bclassid],featherclass='$featherclass'";
		}
		//绑定域名应用于子栏目
		if($add['UrlToSmall']){
			UpdateSmallClassDomain($add['classid'],$add['classurl'],$classpath);
		}
		//wap模板应用于子栏目
		if($add['wapstylesclass'])
		{
			$empire->query("update {$dbtbpre}enewsclass set wapstyleid='$add[wapstyleid]' where featherclass like '%|".$add[classid]."|%'");
		}
		//修改数据库资料
		$sql=$empire->query("update {$dbtbpre}enewsclass set classname='$add[classname]',classpath='$classpath',classtype='$add[classtype]',newline=$add[newline],newstrlen=$add[newstrlen],newshowdate=$add[newshowdate],hotline=$add[hotline],hotstrlen=$add[hotstrlen],hotshowdate=$add[hotshowdate],goodline=$add[goodline],goodstrlen=$add[goodstrlen],goodshowdate=$add[goodshowdate],classurl='$add[classurl]',groupid=$add[groupid],myorder=$add[myorder],filename_qz='$add[filename_qz]',hotplline=$add[hotplline],hotplshowdate=$add[hotplshowdate],hotplstrlen=$add[hotplstrlen],modid=$add[modid],checked=$add[checked],docheckuser=$add[docheckuser],checkuser='$add[checkuser]',firstline=$add[firstline],firststrlen=$add[firststrlen],firstshowdate=$add[firstshowdate],bname='$add[bname]',islist=$add[islist],listtempid=$add[listtempid],lencord=$add[lencord],searchtempid=$add[searchtempid],tid=$tabler[tid],tbname='$tabler[tbname]',maxnum=$add[maxnum],checkpl=$add[checkpl],down_num=$add[down_num],online_num=$add[online_num],listorderf='$add[listorderf]',listorder='$add[listorder]',reorderf='$add[reorderf]',reorder='$add[reorder]',intro='$add[intro]',classimg='$add[classimg]',jstempid=$add[jstempid],listdt=$add[listdt],showclass=$add[showclass],showdt=$add[showdt],qaddgroupid=$add[qaddgroupid],qaddshowkey=$add[qaddshowkey],adminqinfo=$add[adminqinfo],doctime=$add[doctime],classpagekey='$add[classpagekey]',dtlisttempid='$add[dtlisttempid]',classtempid='$add[classtempid]',nreclass=$add[nreclass],nreinfo=$add[nreinfo],nrejs=$add[nrejs],nottobq=$add[nottobq],ipath='$add[ipath]',addreinfo=$add[addreinfo],haddlist=$add[haddlist],sametitle=$add[sametitle],definfovoteid=$add[definfovoteid],wburl='',qeditchecked=$add[qeditchecked],openadd=$add[openadd],wapstyleid='$add[wapstyleid]'".$change." where classid='$add[classid]'");
		GetClass();
		//生成栏目文件
		if(!$add[islist]){
			NewsBq($add[classid],GetClassTemp($add['classtempid']),0,1);
		}
	}
	//终级栏目
	else
	{
		//改变大栏目
		if($add[bclassid]<>$add[oldbclassid]){
			//转到主栏目
			if(empty($add[bclassid])){
				$sonclass="";
				$featherclass="";
				//取得栏目原本的大栏目
				$r=$empire->fetch1("select featherclass,classpath from {$dbtbpre}enewsclass where classid='$add[classid]'");
				//改变原本大栏目的子栏目
				$where=ReturnClass($r[featherclass]);
				if(empty($where)){
					$where="classid=0";
				}
				$bsql=$empire->query("select classid,sonclass from {$dbtbpre}enewsclass where ".$where);
				while($br=$empire->fetch($bsql)){
					$newsonclass=str_replace("|".$add[classid]."|","|",$br[sonclass]);
					$usql=$empire->query("update {$dbtbpre}enewsclass set sonclass='$newsonclass' where classid='$br[classid]'");
				}
			}
			//转到中级栏目
			else
			{
				//取得现在大栏目的值
				$b=$empire->fetch1("select featherclass,islast,wburl from {$dbtbpre}enewsclass where classid='$add[bclassid]'");
				//检测大栏目是否为终级栏目
				if($b[islast])
				{
					printerror("BclassNotLast","");
				}
				if($b[wburl])
				{
					printerror("BclassNotWb","");
				}
				if(empty($b[featherclass])){
					$b[featherclass]="|";
				}
				$featherclass=$b[featherclass].$add[bclassid]."|";
				//改变新大栏目的子栏目
				$where=ReturnClass($featherclass);
				if(empty($where)){
					$where="classid=0";
				}
				$bsql=$empire->query("select sonclass,classid from {$dbtbpre}enewsclass where ".$where);
				while($nb=$empire->fetch($bsql))
				{
					if(empty($nb[sonclass]))
					{$nb[sonclass]="|";}
					$newsonclass=$nb[sonclass].$add[classid]."|";
					$usql=$empire->query("update {$dbtbpre}enewsclass set sonclass='$newsonclass' where classid='$nb[classid]'");
				}
				//改变旧大栏目的子栏目
				$o=$empire->fetch1("select sonclass,featherclass from {$dbtbpre}enewsclass where classid='$add[classid]'");
				$where=ReturnClass($o[featherclass]);
				if(empty($where)){
					$where="classid=0";
				}
				$osql=$empire->query("select sonclass,classid from {$dbtbpre}enewsclass where ".$where);
				while($ob=$empire->fetch($osql)){
				   $newsonclass=str_replace("|".$add[classid]."|","|",$ob[sonclass]);
				   $usql=$empire->query("update {$dbtbpre}enewsclass set sonclass='$newsonclass' where classid='$ob[classid]'");
			   }
			}
			$change=",bclassid=$add[bclassid],featherclass='$featherclass'";
		}
		//应用于已生成的信息
		if($add['tobetempinfo']){
			$upsql=$empire->query("update {$dbtbpre}ecms_".$tabler[tbname]." set newstempid=$add[newstempid] where classid='$add[classid]'");
		}
		//文件前缀
	    $add[filename_qz]=RepFilenameQz($add[filename_qz]);
		$sql=$empire->query("update {$dbtbpre}enewsclass set classname='$add[classname]',classpath='$classpath',classtype='$add[classtype]',link_num=$add[link_num],lencord=$add[lencord],newstempid=$add[newstempid],listtempid=$add[listtempid],newspath='$add[newspath]',filename=$add[filename],filetype='$add[filetype]',openpl=$add[openpl],openadd=$add[openadd],newline=$add[newline],newstrlen=$add[newstrlen],newshowdate=$add[newshowdate],hotline=$add[hotline],hotstrlen=$add[hotstrlen],hotshowdate=$add[hotshowdate],goodline=$add[goodline],goodstrlen=$add[goodstrlen],goodshowdate=$add[goodshowdate],classurl='$add[classurl]',groupid=$add[groupid],myorder=$add[myorder],filename_qz='$add[filename_qz]',hotplline=$add[hotplline],hotplshowdate=$add[hotplshowdate],hotplstrlen=$add[hotplstrlen],modid=$add[modid],checked=$add[checked],docheckuser=$add[docheckuser],checkuser='$add[checkuser]',firstline=$add[firstline],firststrlen=$add[firststrlen],firstshowdate=$add[firstshowdate],bname='$add[bname]',searchtempid=$add[searchtempid],tid=$tabler[tid],tbname='$tabler[tbname]',maxnum=$add[maxnum],checkpl=$add[checkpl],down_num=$add[down_num],online_num=$add[online_num],listorderf='$add[listorderf]',listorder='$add[listorder]',reorderf='$add[reorderf]',reorder='$add[reorder]',intro='$add[intro]',classimg='$add[classimg]',jstempid=$add[jstempid],addinfofen=$add[addinfofen],listdt=$add[listdt],showclass=$add[showclass],showdt=$add[showdt],checkqadd=$add[checkqadd],qaddlist=$add[qaddlist],qaddgroupid=$add[qaddgroupid],qaddshowkey=$add[qaddshowkey],adminqinfo=$add[adminqinfo],doctime=$add[doctime],classpagekey='$add[classpagekey]',dtlisttempid='$add[dtlisttempid]',classtempid='$add[classtempid]',nreclass=$add[nreclass],nreinfo=$add[nreinfo],nrejs=$add[nrejs],nottobq=$add[nottobq],ipath='$add[ipath]',addreinfo=$add[addreinfo],haddlist=$add[haddlist],sametitle=$add[sametitle],definfovoteid=$add[definfovoteid],wburl='',qeditchecked=$add[qeditchecked],wapstyleid='$add[wapstyleid]'".$change." where classid='$add[classid]'");
		GetClass();
	}
	//移动目录
	if($add[bclassid]<>$add[oldbclassid]){
		$opath="../../".$add[oldclasspath];
		$newpath="../../".$classpath;
		MovePath($opath,$newpath);
		$opath="../../d/file/".$add[oldclasspath];
		$npath="../../d/file/".$classpath;
		CopyPath($opath,$npath);
    }
	else{
		if($add['oldcpath']<>$add['classpath'])//更换栏目目录
		{
			AlterClassPath($add['classid'],$add['islast'],$add['oldclasspath'],$classpath);
			GetClass();
		}
	}
	//删除缓存文件
	if($add[oldclassname]<>$add[classname]||$add[bclassid]<>$add[oldbclassid]){
		DelListEnews();
		GetSearch($add[modid]);
    }
	else{
		if($add[openadd]<>$add[oldopenadd]||$add[modid]<>$add[oldmodid]){
			GetSearch($add[modid]);
			if($add[modid]<>$add[oldmodid]){
				GetSearch($add[oldmodid]);
			}
		}
	}
	//修改栏目扩展名
	if($add[oldclasstype]<>$add[classtype]){
		$todaytime=date("Y-m-d H:i:s");
		if($add[islast]){
			$query="select count(*) as total from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where checked=1 and classid='$add[classid]'";
			$lencord=$add[oldlencord];
			$num=$empire->gettotal($query);
		}
		else{
			$lencord=$add[oldlencord];
			if($add[oldislist]){
				$where=ReturnClass($class_r[$add[classid]][sonclass]);
				$query="select count(*) as total from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where checked=1 and (".$where.")";
				$num=$empire->gettotal($query);
			}
			else
			{
				$num=1;
			}
		}
		RenameListfile($add[classid],$lencord,$num,$add[oldclasstype],$add[classtype],$classpath);
	}
	//来源
	if($add['from']){
		$returnurl="ListPageClass.php";
	}
	else{
		$returnurl="ListClass.php";
	}
	TogNotReClass(1);
	if($sql){
		insert_dolog("classid=".$add[classid]."<br>classname=".$add[classname]);//操作日志
		printerror("EditClassSuccess",$returnurl);
	}
	else{
		printerror("DbError","history.go(-1)");
	}
}

//终极栏目与非终极栏目之间的转换
function ChangeClassIslast($reclassid,$userid,$username){
	global $empire,$dbtbpre;
	//操作权限
	CheckLevel($userid,$username,$classid,"class");
	$count=count($reclassid);
	$classid=(int)$reclassid[0];
	if($count==0||!$classid)
	{
		printerror("NotChangeIslastClassid","");
	}
	//取得本栏目信息
	$r=$empire->fetch1("select classid,sonclass,featherclass,islist,islast,classname,modid,tbname,wburl from {$dbtbpre}enewsclass where classid=$classid");
	if(empty($r[classid]))
	{
		printerror("NotChangeIslastClassid","");
	}
	if($r[wburl])
	{
		printerror("NotChangeWbClassid","");
	}
	//非终极栏目
	if(!$r[islast])
	{
		$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsclass where bclassid=$classid");
		if($num)
		{
			printerror("LastTheClassHaveSonclass","history.go(-1)");
		}
		//修改父栏目的子栏目
		$where=ReturnClass($r[featherclass]);
		if(empty($where))
		{
			$where="classid=0";
		}
		$sql=$empire->query("select classid,sonclass from {$dbtbpre}enewsclass where ".$where);
		while($br=$empire->fetch($sql))
		{
			if(empty($br[sonclass]))
			{
				$br[sonclass]="|";
			}
			$newsonclass=$br[sonclass].$classid."|";
			$usql=$empire->query("update {$dbtbpre}enewsclass set sonclass='$newsonclass' where classid=$br[classid]");
		}
		$dosql=$empire->query("update {$dbtbpre}enewsclass set islast=1 where classid=$classid");
		$mess="ChangeClassToLastSuccess";
	}
	//终极栏目
	else
	{
		$num=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$r[tbname]." where classid=$classid");
		if($num)
		{
			printerror("LastTheClassHaveInfo","history.go(-1)");
		}
		//修改父栏目的子栏目
		$where=ReturnClass($r[featherclass]);
		if(empty($where))
		{
			$where="classid=0";
		}
		$sql=$empire->query("select classid,sonclass from {$dbtbpre}enewsclass where ".$where);
		while($br=$empire->fetch($sql))
		{
			if(empty($br[sonclass]))
			{
				$br[sonclass]="|";
			}
			$newsonclass=str_replace("|".$classid."|","|",$br[sonclass]);
			$usql=$empire->query("update {$dbtbpre}enewsclass set sonclass='$newsonclass' where classid=$br[classid]");
		}
		$dosql=$empire->query("update {$dbtbpre}enewsclass set islast=0 where classid=$classid");
		$mess="ChangeClassToNolastSuccess";
	}
	//删除缓存文件
	DelListEnews();
	//更新缓存
	GetClass();
	GetSearch($r[modid]);
	if($dosql)
	{
		//操作日志
		insert_dolog("classid=".$classid."<br>classname=".$r[classname]);
		printerror($mess,$_SERVER['HTTP_REFERER']);
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//删除栏目
function DelClass($classid,$userid,$username){
	global $empire,$dbtbpre;
	$classid=(int)$classid;
	if(!$classid)
	{
		printerror("NotDelClassid","");
	}
	//操作权限
	CheckLevel($userid,$username,$classid,"class");
	$r=$empire->fetch1("select * from {$dbtbpre}enewsclass where classid='$classid'");
	if(empty($r[classid]))
	{
		printerror("NotClassid","history.go(-1)");
	}
    DelClass1($classid);
    GetClass();
	GetSearch($r[modid]);
	//返回地址
	if($_GET['from'])
	{$returnurl="ListPageClass.php";}
	else
	{$returnurl="ListClass.php";}
	TogNotReClass(1);
	insert_dolog("classid=".$classid."<br>classname=".$r[classname]);//操作日志
	printerror("DelClassSuccess",$returnurl);
}

//删除栏目,不返回值
function DelClass1($classid){
	global $empire,$class_r,$dbtbpre;
	$r=$empire->fetch1("select * from {$dbtbpre}enewsclass where classid='$classid'");
	//外部栏目
	if($r[wburl])
	{
		$sql=$empire->query("delete from {$dbtbpre}enewsclass where classid='$classid'");
		//删除缓存
		DelListEnews();
		return "";
	}
	//删除终极栏目
	if($r[islast])
	{
		//删除附件
		DelClassTranFile($classid);
		$filepath="../../d/file/".$r[classpath];
		$delf=DelPath($filepath);
		$usql=$empire->query("delete from {$dbtbpre}enewsfile where classid='$classid'");
		//删除信息
		$sql=$empire->query("delete from {$dbtbpre}ecms_".$r[tbname]." where classid='$classid'");
		//删除信息附加表
		$delsql=$empire->query("delete from {$dbtbpre}enewsqf where classid='$classid'");
		$delsql=$empire->query("delete from {$dbtbpre}enewsinfovote where classid='$classid'");
		$delsql=$empire->query("delete from {$dbtbpre}enewsdiggips where classid='$classid'");
		//删除栏目本身
	    $sql1=$empire->query("delete from {$dbtbpre}enewsclass where classid='$classid'");
		$delpath="../../".$r[classpath];
		$del=DelPath($delpath);
		//更新大栏目的子栏目
		$where=ReturnClass($r[featherclass]);
	    if(empty($where))
		{$where="classid=0";}
	    $bsql=$empire->query("select sonclass,classid from {$dbtbpre}enewsclass where ".$where);
		while($br=$empire->fetch($bsql))
		{
			$newsonclass=str_replace("|".$classid."|","|",$br[sonclass]);
			$usql=$empire->query("update {$dbtbpre}enewsclass set sonclass='$newsonclass' where classid='$br[classid]'");
		}
	}
	//删除大栏目
	else
	{
	    //删除栏目
		$where=ReturnClass($r[sonclass]);
		if(empty($where))
		{$where="classid=0";}
		$delcr=explode("|",$r[sonclass]);
		$count=count($delcr);
		for($i=1;$i<$count-1;$i++)
		{
			$delcid=$delcr[$i];
			//删除附件
			DelClassTranFile($delcid);
			$sql=$empire->query("delete from {$dbtbpre}ecms_".$class_r[$delcid][tbname]." where classid='$delcid'");
			//删除信息附加表
			$delsql=$empire->query("delete from {$dbtbpre}enewsqf where classid='$delcid'");
			$delsql=$empire->query("delete from {$dbtbpre}enewsinfovote where classid='$delcid'");
			$delsql=$empire->query("delete from {$dbtbpre}enewsdiggips where classid='$delcid'");
		}
		//删除附件
		$filepath="../../d/file/".$r[classpath];
	    $delf=DelPath($filepath);
		if($where<>'classid=0')
		{
			$usql=$empire->query("delete from {$dbtbpre}enewsfile where ".$where);
		}
		//删除子栏目
		$sql1=$empire->query("delete from {$dbtbpre}enewsclass where featherclass like '%|".$classid."|%'");
		//改变父栏目的子类
		$where=ReturnClass($r[featherclass]);
		if(empty($where))
		{$where="classid=0";}
		$bbsql=$empire->query("select classid,sonclass from {$dbtbpre}enewsclass where ".$where);
		while($bbr=$empire->fetch($bbsql))
		{
			$newsonclass=str_replace($r[sonclass],"|",$bbr[sonclass]);
			$usql=$empire->query("update {$dbtbpre}enewsclass set sonclass='$newsonclass' where classid='$bbr[classid]'");
		}
		//删除栏目本身
		$sql2=$empire->query("delete from {$dbtbpre}enewsclass where classid='$classid'");
		$delpath="../../".$r[classpath];
		$del=DelPath($delpath);
	}
	//删除缓存
	DelListEnews();
}

//删除栏目附件
function DelClassTranFile($classid){
	global $empire,$class_r,$dbtbpre;
	//删除文本
	if(strstr($public_r['savetxtf'],",".$class_r[$r[classid]][tbname].".newstext,"))
	{
		$txtsql=$empire->query("select newstext from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where classid='$classid'");
		while($txtr=$empire->fetch($txtsql))
		{
			$newstextfile=$txtr[newstext];
			$txtr[newstext]=GetTxtFieldText($txtr[newstext]);
			DelTxtFieldText($newstextfile);//删除文件
		}
	}
	//删除附件
	$filesql=$empire->query("select id from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where classid='$classid'");
	while($filer=$empire->fetch($filesql))
	{
		DelNewsTheFile($filer[id],$classid);//删除附件
	}
}

//参数设置
function SetEnews($add,$userid,$username){
	global $empire,$dbtbpre;
	//操作权限
	CheckLevel($userid,$username,$classid,"public");
	if(empty($add[indextype])){
		$add[indextype]=".html";
	}
	if(empty($add[searchtype])){
		$add[searchtype]=".html";
	}
	//备份目录
	if(empty($add[bakdbpath])){
		$add[bakdbpath]="bdata";
	}
	if(!file_exists("ebak/".RepPathStr($add[bakdbpath])))
	{
		printerror("NotBakDbPath","");
	}
	if(empty($add[bakdbzip])){
		$add[bakdbzip]="zip";
	}
	if(!file_exists("ebak/".RepPathStr($add[bakdbzip]))){
		printerror("NotbakZipPath","");
	}
	if(empty($add[down_num])){
		$add[down_num]=1;
	}
	//函数是否存在
    if(!function_exists($add['listpagefun'])||!function_exists($add['textpagefun'])||!function_exists($add['listpagelistfun']))
	{
		printerror("NotPageFun","history.go(-1)");
    }
	//adfile
	$add['adfile']=RepFilenameQz($add['adfile']);
	//修改ftp密码
	if($add[changeftpp]){
		$a="ftppassword='$add[ftppassword]',";
    }
	//变量处理
	$add[filesize]=(int)$add[filesize];
	$add[hotnum]=(int)$add[hotnum];
	$add[newnum]=(int)$add[newnum];
	$add[sub_hot]=(int)$add[sub_hot];
	$add[sub_new]=(int)$add[sub_new];
	$add[relistnum]=(int)$add[relistnum];
	$add[renewsnum]=(int)$add[renewsnum];
	$add[min_keyboard]=(int)$add[min_keyboard];
	$add[max_keyboard]=(int)$add[max_keyboard];
	$add[search_num]=(int)$add[search_num];
	$add[search_pagenum]=(int)$add[search_pagenum];
	$add[newslink]=(int)$add[newslink];
	$add[checked]=(int)$add[checked];
	$add[pltime]=(int)$add[pltime];
	$add[searchtime]=(int)$add[searchtime];
	$add[loginnum]=(int)$add[loginnum];
	$add[logintime]=(int)$add[logintime];
	$add[addnews_ok]=(int)$add[addnews_ok];
	$add[register_ok]=(int)$add[register_ok];
	$add[goodlencord]=(int)$add[goodlencord];
	$add[goodnum]=(int)$add[goodnum];
	$add[sub_good]=(int)$add[sub_good];
	$add[exittime]=(int)$add[exittime];
	$add[smalltextlen]=(int)$add[smalltextlen];
	$add[defaultgroupid]=(int)$add[defaultgroupid];
	$add[phpmode]=(int)$add[phpmode];
	$add[install]=(int)$add[install];
	$add[searchsubnews]=(int)$add[searchsubnews];
	$add[plsize]=(int)$add[plsize];
	$add[plincludesize]=(int)$add[plincludesize];
	$add[hotshowdate]=(int)$add[hotshowdate];
	$add[newshowdate]=(int)$add[newshowdate];
	$add[goodshowdate]=(int)$add[goodshowdate];
	$add[hotplnum]=(int)$add[hotplnum];
	$add[sub_hotpl]=(int)$add[sub_hotpl];
	$add[hotplshowdate]=(int)$add[hotplshowdate];
	$add[dorepnum]=(int)$add[dorepnum];
	$add[loadtempnum]=(int)$add[loadtempnum];
	$add[firstnum]=(int)$add[firstnum];
	$add[sub_first]=(int)$add[sub_first];
	$add[firstshowdate]=(int)$add[firstshowdate];
	$add[down_num]=(int)$add[down_num];
	$add[min_userlen]=(int)$add[min_userlen];
	$add[max_userlen]=(int)$add[max_userlen];
	$add[min_passlen]=(int)$add[min_passlen];
	$add[max_passlen]=(int)$add[max_passlen];
	$add[filechmod]=(int)$add[filechmod];
	$add[sametitle]=(int)$add[sametitle];
	$add[addrehtml]=(int)$add[addrehtml];
	$add[loginkey_ok]=(int)$add[loginkey_ok];
	$add[limittype]=(int)$add[limittype];
	$add[plkey_ok]=(int)$add[plkey_ok];
	$add[redodown]=(int)$add[redodown];
	$add[fpnum]=(int)$add[fpnum];
	$add[havefp]=(int)$add[havefp];
	$add[candocode]=(int)$add[candocode];
	$add[opennotcj]=(int)$add[opennotcj];
	$add[reuserpagenum]=(int)$add[reuserpagenum];
	$add[revotejsnum]=(int)$add[revotejsnum];
	$add[readjsnum]=(int)$add[readjsnum];
	$add[qaddtran]=(int)$add[qaddtran];
	$add[qaddtransize]=(int)$add[qaddtransize];
	$add[ebakthisdb]=(int)$add[ebakthisdb];
	$add[delnewsnum]=(int)$add[delnewsnum];
	$add[openclasspv]=(int)$add[openclasspv];
	$add[openpagepv]=(int)$add[openpagepv];
	$add[markpos]=(int)$add[markpos];
	$add[adminloginkey]=(int)$add[adminloginkey];
	$add[php_outtime]=(int)$add[php_outtime];
	$add[addreinfo]=(int)$add[addreinfo];
	$add[rssnum]=(int)$add[rssnum];
	$add[rsssub]=(int)$add[rsssub];
	$add[dorepdlevelnum]=(int)$add[dorepdlevelnum];
	$add[listpagelistnum]=(int)$add[listpagelistnum];
	$add[infolinknum]=(int)$add[infolinknum];
	$add[searchgroupid]=(int)$add[searchgroupid];
	$add[opencopytext]=(int)$add[opencopytext];
	$add[reuserjsnum]=(int)$add[reuserjsnum];
	$add[reuserlistnum]=(int)$add[reuserlistnum];
	$add[opentitleurl]=(int)$add[opentitleurl];
	$add['qaddtranfile']=(int)$add['qaddtranfile'];
	$add['qaddtranfilesize']=(int)$add['qaddtranfilesize'];
	$add['sendmailtype']=(int)$add['sendmailtype'];
	$add['loginemail']=(int)$add['loginemail'];
	$add['feedbacktfile']=(int)$add['feedbacktfile'];
	$add['feedbackfilesize']=(int)$add['feedbackfilesize'];
	$add['searchtempvar']=(int)$add['searchtempvar'];
	$add['showinfolevel']=(int)$add['showinfolevel'];
	$add['spicwidth']=(int)$add['spicwidth'];
	$add['spicheight']=(int)$add['spicheight'];
	$add['spickill']=(int)$add['spickill'];
	$add['jpgquality']=(int)$add['jpgquality'];
	$add['markpct']=(int)$add['markpct'];
	$add['redoview']=(int)$add['redoview'];
	$add['reggetfen']=(int)$add['reggetfen'];
	$add['regbooktime']=(int)$add['regbooktime'];
	$add['revotetime']=(int)$add['revotetime'];
	$add['fpath']=(int)$add['fpath'];
	$add['openmembertranimg']=(int)$add['openmembertranimg'];
	$add['memberimgsize']=(int)$add['memberimgsize'];
	$add['openmembertranfile']=(int)$add['openmembertranfile'];
	$add['memberfilesize']=(int)$add['memberfilesize'];
	$add['openspace']=(int)$add['openspace'];
	$add['realltime']=(int)$add['realltime'];
	$add['plfacenum']=(int)$add['plfacenum'];
	$add['textpagelistnum']=(int)$add['textpagelistnum'];
	$add['memberlistlevel']=(int)$add['memberlistlevel'];
	$add['ebakcanlistdb']=(int)$add['ebakcanlistdb'];

	$add[filetype]="|".$add[filetype]."|";
	$add[qimgtype]="|".$add['qaddtranimgtype']."|";
	$add[qfiletype]="|".$add['qaddtranfiletype']."|";
	$add[feedbackfiletype]="|".$add['feedbackfiletype']."|";
	$add[memberimgtype]="|".$add['memberimgtype']."|";
	$add[memberfiletype]="|".$add['memberfiletype']."|";
	$sql=$empire->query("update {$dbtbpre}enewspublic set ".$a."sitename='$add[sitename]',siteurl='$add[siteurl]',newsurl='$add[newsurl]',email='$add[email]',filetype='$add[filetype]',filesize=$add[filesize],hotnum=$add[hotnum],newnum=$add[newnum],sub_hot=$add[sub_hot],sub_new=$add[sub_new],relistnum=$add[relistnum],renewsnum=$add[renewsnum],min_keyboard=$add[min_keyboard],max_keyboard=$add[max_keyboard],search_num=$add[search_num],search_pagenum=$add[search_pagenum],newslink=$add[newslink],search_color='$add[search_color]',checked=$add[checked],pltime=$add[pltime],searchtime=$add[searchtime],loginnum=$add[loginnum],logintime=$add[logintime],addnews_ok=$add[addnews_ok],register_ok=$add[register_ok],indextype='$add[indextype]',goodlencord=$add[goodlencord],goodtype='$add[goodtype]',goodnum=$add[goodnum],sub_good=$add[sub_good],searchtype='$add[searchtype]',exittime=$add[exittime],smalltextlen=$add[smalltextlen],defaultgroupid=$add[defaultgroupid],fileurl='$add[fileurl]',phpmode=$add[phpmode],ftphost='$add[ftphost]',ftpport='$add[ftpport]',ftpusername='$add[ftpusername]',ftppath='$add[ftppath]',ftpmode='$add[ftpmode]',install=$add[install],searchsubnews=$add[searchsubnews],plsize=$add[plsize],plincludesize=$add[plincludesize],hotshowdate=$add[hotshowdate],newshowdate=$add[newshowdate],goodshowdate=$add[goodshowdate],hotplnum=$add[hotplnum],sub_hotpl=$add[sub_hotpl],hotplshowdate=$add[hotplshowdate],dorepnum=$add[dorepnum],loadtempnum=$add[loadtempnum],firstnum=$add[firstnum],sub_first=$add[sub_first],firstshowdate=$add[firstshowdate],bakdbpath='$add[bakdbpath]',bakdbzip='$add[bakdbzip]',downpass='$add[downpass]',dwwidth='$add[dwwidth]',dwheight='$add[dwheight]',down_num=$add[down_num],min_userlen=$add[min_userlen],max_userlen=$add[max_userlen],min_passlen=$add[min_passlen],max_passlen=$add[max_passlen],filechmod=$add[filechmod],loginkey_ok=$add[loginkey_ok],limittype=$add[limittype],plkey_ok=$add[plkey_ok],redodown=$add[redodown],fpnum=$add[fpnum],havefp=$add[havefp],candocode=$add[candocode],opennotcj=$add[opennotcj],reuserpagenum=$add[reuserpagenum],revotejsnum=$add[revotejsnum],readjsnum=$add[readjsnum],qaddtran=$add[qaddtran],qaddtransize=$add[qaddtransize],ebakthisdb=$add[ebakthisdb],delnewsnum=$add[delnewsnum],openclasspv=$add[openclasspv],openpagepv=$add[openpagepv],markpos=$add[markpos],markimg='$add[markimg]',marktext='$add[marktext]',markfontsize='$add[markfontsize]',markfontcolor='$add[markfontcolor]',markfont='$add[markfont]',adminloginkey=$add[adminloginkey],php_outtime=$add[php_outtime],listpagefun='$add[listpagefun]',textpagefun='$add[textpagefun]',adfile='$add[adfile]',notsaveurl='$add[notsaveurl]',rssnum=$add[rssnum],rsssub=$add[rsssub],dorepdlevelnum=$add[dorepdlevelnum],listpagelistfun='$add[listpagelistfun]',listpagelistnum=$add[listpagelistnum],infolinknum=$add[infolinknum],searchgroupid=$add[searchgroupid],opencopytext=$add[opencopytext],reuserjsnum=$add[reuserjsnum],reuserlistnum=$add[reuserlistnum],opentitleurl='$add[opentitleurl]',qaddtranimgtype='$add[qimgtype]',qaddtranfile=$add[qaddtranfile],qaddtranfilesize=$add[qaddtranfilesize],qaddtranfiletype='$add[qfiletype]',sendmailtype=$add[sendmailtype],smtphost='$add[smtphost]',fromemail='$add[fromemail]',loginemail=$add[loginemail],emailusername='$add[emailusername]',emailpassword='$add[emailpassword]',smtpport='$add[smtpport]',emailname='$add[emailname]',feedbacktfile=$add[feedbacktfile],feedbackfilesize=$add[feedbackfilesize],feedbackfiletype='$add[feedbackfiletype]',searchtempvar=$add[searchtempvar],showinfolevel=$add[showinfolevel],navfh='".addslashes($add[navfh])."',spicwidth=$add[spicwidth],spicheight=$add[spicheight],spickill=$add[spickill],jpgquality=$add[jpgquality],markpct=$add[markpct],redoview=$add[redoview],reggetfen=$add[reggetfen],regbooktime=$add[regbooktime],revotetime=$add[revotetime],fpath=$add[fpath],filepath='$add[filepath]',openmembertranimg=$add[openmembertranimg],memberimgsize=$add[memberimgsize],openmembertranfile=$add[openmembertranfile],memberfilesize=$add[memberfilesize],memberimgtype='$add[memberimgtype]',memberfiletype='$add[memberfiletype]',canposturl='$add[canposturl]',openspace='$add[openspace]',realltime=$add[realltime],closeip='$add[closeip]',openip='$add[openip]',hopenip='$add[hopenip]',plfacenum=$add[plfacenum],closewords='$add[closewords]',closewordsf='$add[closewordsf]',textpagelistnum=$add[textpagelistnum],memberlistlevel=$add[memberlistlevel],ebakcanlistdb=$add[ebakcanlistdb];");
	GetConfig();
	if($sql){
		insert_dolog("");//操作日志
		printerror("SetPublicSuccess","SetEnews.php");
	}
	else{
		printerror("DbError","history.go(-1)");
	}
}

//增加会员字段
function AddMemberF($add,$userid,$username){
	global $empire,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"memberf");
	$add[f]=RepPostVar($add[f]);
	if(empty($add[f])||empty($add[fname]))
	{
		printerror("EmptyF","");
	}
	//字段是否重复
	$s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewsmemberadd");
	$b=0;
	while($r=$empire->fetch($s))
	{
		if($r[Field]==$add[f])
		{
			$b=1;
			break;
		}
    }
	if($b)
	{
		printerror("ReF","");
	}
	$s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewsmember");
	$b=0;
	while($r=$empire->fetch($s))
	{
		if($r[Field]==$add[f])
		{
			$b=1;
			break;
		}
    }
	if($b)
	{
		printerror("ReF","");
	}
	$add[fvalue]=ReturnFvalue($add[fvalue]);//初始化值
	//字段类型
	if($add[ftype]=="TINYINT"||$add[ftype]=="SMALLINT"||$add[ftype]=="INT"||$add[ftype]=="BIGINT"||$add[ftype]=="FLOAT"||$add[ftype]=="DOUBLE")
	{
		$def=" default '0'";
	}
	elseif($add[ftype]=="VARCHAR")
	{
		$def=" default ''";
	}
	else
	{
		$def="";
	}
	$type=$add[ftype];
	//VARCHAR
	if($add[ftype]=='VARCHAR'&&empty($add[flen]))
	{
		$add[flen]='255';
	}
	//字段长度
	if($add[flen]){
		if($add[ftype]!="TEXT"&&$add[ftype]!="MEDIUMTEXT"&&$add[ftype]!="LONGTEXT"){
			$type.="(".$add[flen].")";
		}
	}
	$field="`".$add[f]."` ".$type." NOT NULL".$def;
	//新增字段
	$asql=$empire->query("alter table {$dbtbpre}enewsmemberadd add ".$field);
	//替换代码
	$fhtml=GetMemberFform($add[fform],$add[f],$add[fvalue],$add[fformsize]);
	if($add[fform]=='select'||$add[fform]=='radio'||$add[fform]=='checkbox')
	{
		$fhtml=str_replace("\$r[","\$addr[",$fhtml);
	}
	//处理变量
	$add[myorder]=(int)$add[myorder];
	$sql=$empire->query("insert into {$dbtbpre}enewsmemberf(f,fname,fform,fhtml,fzs,myorder,ftype,flen,fvalue,fformsize) values('$add[f]','$add[fname]','$add[fform]','".addslashes($fhtml)."','".addslashes($add[fzs])."',$add[myorder],'$add[ftype]','$add[flen]','".addslashes($add[fvalue])."','$add[fformsize]');");
	$lastid=$empire->lastid();
	if($asql&&$sql)
	{
		//操作日志
		insert_dolog("fid=".$lastid."<br>f=".$add[f]);
		printerror("AddFSuccess","member/AddMemberF.php?enews=AddMemberF");
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//修改会员字段
function EditMemberF($add,$userid,$username){
	global $empire,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"memberf");
	$fid=(int)$add['fid'];
	$add[f]=RepPostVar($add[f]);
	$add[oldf]=RepPostVar($add[oldf]);
	if(empty($add[f])||empty($add[fname])||!$fid){
		printerror("EmptyF","history.go(-1)");
	}
	if($add[f]<>$add[oldf]){
		//字段是否重复
		$s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewsmemberadd");
		$b=0;
		while($r=$empire->fetch($s)){
			if($r[Field]==$add[f]){
				$b=1;
				break;
			}
		}
		if($b){
			printerror("ReF","history.go(-1)");
		}
		$s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewsmember");
		$b=0;
		while($r=$empire->fetch($s))
		{
			if($r[Field]==$add[f])
			{
				$b=1;
				break;
			}
		}
		if($b)
		{
			printerror("ReF","");
		}
	}
	$add[fvalue]=ReturnFvalue($add[fvalue]);//初始化值
	//字段类型
	if($add[ftype]=="TINYINT"||$add[ftype]=="SMALLINT"||$add[ftype]=="INT"||$add[ftype]=="BIGINT"||$add[ftype]=="FLOAT"||$add[ftype]=="DOUBLE")
	{
		$def=" default '0'";
	}
	elseif($add[ftype]=="VARCHAR")
	{
		$def=" default ''";
	}
	else
	{
		$def="";
	}
	$type=$add[ftype];
	//VARCHAR
	if($add[ftype]=='VARCHAR'&&empty($add[flen]))
	{
		$add[flen]='255';
	}
	//字段长度
	if($add[flen]){
		if($add[ftype]!="TEXT"&&$add[ftype]!="MEDIUMTEXT"&&$add[ftype]!="LONGTEXT"){
			$type.="(".$add[flen].")";
		}
	}
	$field="`".$add[f]."` ".$type." NOT NULL".$def;
	$usql=$empire->query("alter table {$dbtbpre}enewsmemberadd change `".$add[oldf]."` ".$field);
	//替换代码
	if($add[f]<>$add[oldf]||$add[fform]<>$add[oldfform]||$add[fvalue]<>$add[oldfvalue]||$add[fformsize]<>$add[oldfformsize]){
		$fhtml=GetMemberFform($add[fform],$add[f],$add[fvalue],$add[fformsize]);
		if($add[fform]=='select'||$add[fform]=='radio'||$add[fform]=='checkbox')
		{
			$fhtml=str_replace("\$r[","\$addr[",$fhtml);
		}
	}
	else{
		$fhtml=$add[fhtml];
	}
	//处理变量
	$add[myorder]=(int)$add[myorder];
	$sql=$empire->query("update {$dbtbpre}enewsmemberf set f='$add[f]',fname='$add[fname]',fform='$add[fform]',fhtml='".addslashes($fhtml)."',fzs='".addslashes($add[fzs])."',myorder=$add[myorder],ftype='$add[ftype]',flen='$add[flen]',fvalue='".addslashes($add[fvalue])."',fformsize='$add[fformsize]' where fid=$fid");
	//更新表单
	$record="<!--record-->";
	$field="<!--field--->";
	$like=$field.$add[oldf].$record;
	$newlike=$field.$add[f].$record;
	$slike=",".$add[oldf].",";
	$newslike=",".$add[f].",";
	$csql=$empire->query("select fid,ftemp,enter,mustenter,filef,imgf,tobrf,viewenter from {$dbtbpre}enewsmemberform where enter like '%$like%'");
	while($cr=$empire->fetch($csql))
	{
		$setf="";
		$newftemp=str_replace('[!--'.$add[oldf].'--]','[!--'.$add[f].'--]',stripSlashes($cr['ftemp']));
		$setf.=",ftemp='".addslashes($newftemp)."'";
		if(strstr($cr['mustenter'],$slike)){
			$setf.=",mustenter=REPLACE(mustenter,'$slike','$newslike')";
		}
		if(strstr($cr['filef'],$slike)){
			$setf.=",filef=REPLACE(filef,'$slike','$newslike')";
		}
		if(strstr($cr['imgf'],$slike)){
			$setf.=",imgf=REPLACE(imgf,'$slike','$newslike')";
		}
		if(strstr($cr['tobrf'],$slike)){
			$setf.=",tobrf=REPLACE(tobrf,'$slike','$newslike')";
		}
		if(strstr($cr[viewenter],$like)){
			$setf.=",viewenter=REPLACE(viewenter,'$like','$newlike')";
		}
		$cusql=$empire->query("update {$dbtbpre}enewsmemberform set enter=REPLACE(enter,'$like','$newlike')".$setf." where fid='$cr[fid]'");
		//生成表单页面
		ChangeMemberForm($cr[fid],$newftemp);
	}
	if($usql&&$sql)
	{
		insert_dolog("fid=".$fid."<br>f=".$add[f]);//操作日志
		printerror("EditFSuccess","member/ListMemberF.php");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//删除会员字段
function DelMemberF($add,$userid,$username){
	global $empire,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"memberf");
	$fid=(int)$add['fid'];
	if(empty($fid)){
		printerror("EmptyFid","history.go(-1)");
	}
	$r=$empire->fetch1("select f from {$dbtbpre}enewsmemberf where fid=$fid");
	if(!$r[f]){
		printerror("EmptyFid","history.go(-1)");
	}
	$usql=$empire->query("alter table {$dbtbpre}enewsmemberadd drop COLUMN `".$r[f]."`");
	$sql=$empire->query("delete from {$dbtbpre}enewsmemberf where fid=$fid");
	//更新表单表
	$record="<!--record-->";
	$field="<!--field--->";
	$like=$field.$r[f].$record;
	$slike=",".$r[f].",";
	$csql=$empire->query("select fid,ftemp,enter,mustenter,filef,imgf,tobrf,viewenter from {$dbtbpre}enewsmemberform where enter like '%$like%'");
	while($cr=$empire->fetch($csql))
	{
		$setf="";
		if(strstr($cr['mustenter'],$slike))
		{
			$setf.=",mustenter=REPLACE(mustenter,'$slike',',')";
		}
		if(strstr($cr['filef'],$slike))
		{
			$setf.=",filef=REPLACE(filef,'$slike',',')";
		}
		if(strstr($cr['imgf'],$slike))
		{
			$setf.=",imgf=REPLACE(imgf,'$slike',',')";
		}
		if(strstr($cr['tobrf'],$slike))
		{
			$setf.=",tobrf=REPLACE(tobrf,'$slike',',')";
		}
		//录入项
		$enter="";
		$re1=explode($record,$cr[enter]);
		for($i=0;$i<count($re1)-1;$i++)
		{
			if(strstr($re1[$i],$like))
			{continue;}
			$enter.=$re1[$i].$record;
		}
		//前台显示
		if(strstr($cr[viewenter],$like)){
			$viewenter='';
			$re2=explode($record,$cr[viewenter]);
			for($i=0;$i<count($re2)-1;$i++){
				if(strstr($re2[$i],$like)){
					continue;
				}
				$viewenter.=$re2[$i].$record;
			}
			$setf.=",viewenter='".$viewenter."'";
		}
		$cusql=$empire->query("update {$dbtbpre}enewsmemberform set enter='$enter'".$setf." where fid='$cr[fid]'");
	}
	if($usql&&$sql)
	{
		insert_dolog("fid=".$fid."<br>f=".$r[f]);//操作日志
		printerror("DelFSuccess","member/ListMemberF.php");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改会员字段顺序
function EditMemberFOrder($fid,$myorder,$userid,$username){
	global $empire,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"memberf");
	for($i=0;$i<count($myorder);$i++)
	{
		$newmyorder=(int)$myorder[$i];
		$usql=$empire->query("update {$dbtbpre}enewsmemberf set myorder=$newmyorder where fid='$fid[$i]'");
    }
	printerror("EditFOrderSuccess","member/ListMemberF.php");
}

//返回自动生成会员表单模板
function ReturnMemberFtemp($cname,$center){
	$temp="<tr><td width='16%' height=25 bgcolor='ffffff'>enews.name</td><td bgcolor='ffffff'>[!--enews.var--]</td></tr>";
	for($i=0;$i<count($center);$i++){
		$v=$center[$i];
		$data.=str_replace("enews.var",$v,str_replace("enews.name",$cname[$v],$temp));
    }
	return "<table width='100%' align='center' cellpadding=3 cellspacing=1 bgcolor='#DBEAF5'>".$data."</table>";
}

//更新会员表单文件
function ChangeMemberForm($fid,$mtemp){
	global $empire,$dbtbpre;
	$file="../data/html/memberform".$fid.".php";
	$sql=$empire->query("select f,fhtml from {$dbtbpre}enewsmemberf");
	while($r=$empire->fetch($sql)){
		$mtemp=str_replace("[!--".$r[f]."--]",$r[fhtml],$mtemp);
    }
	$mtemp="<?php
if(!defined('InEmpireCMS'))
{exit();}
?>".$mtemp;
	WriteFiletext($file,$mtemp);
}

//增加会员表单
function AddMemberForm($add,$userid,$username){
	global $empire,$dbtbpre;
	if(empty($add[fname]))
	{
		printerror("EmptyMemberForm","");
	}
	//验证权限
	CheckLevel($userid,$username,$classid,"memberf");
	$enter=TogMqenter($add['cname'],$add['center']);
	$viewenter=TogMqenter($add['cname'],$add['venter']);
	$mustenter=TogMustf($add['cname'],$add['menter']);
	$filef=ReturnMFileF($enter,$dbtbpre."enewsmemberf",0,"file");
	$imgf=ReturnMFileF($enter,$dbtbpre."enewsmemberf",0,"img");
	$tobrf=ReturnMFileF($enter,$dbtbpre."enewsmemberf",0,"textarea");
	//自动生成表单
	if($add[ftype])
	{
		$add[ftemp]=ReturnMemberFtemp($add['cname'],$add['center']);
	}
	$sql=$empire->query("insert into {$dbtbpre}enewsmemberform(fname,ftemp,fzs,enter,mustenter,filef,imgf,tobrf,viewenter) values('$add[fname]','".addslashes($add[ftemp])."','".addslashes($add[fzs])."','$enter','$mustenter','$filef','$imgf','$tobrf','$viewenter');");
	$fid=$empire->lastid();
	//生成表单页面
	ChangeMemberForm($fid,$add[ftemp]);
	if($sql)
	{
	    insert_dolog("fid=".$fid."<br>fname=".$add[fname]);//操作日志
		printerror("AddMemberFormSuccess","member/AddMemberForm.php?enews=AddMemberForm");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改会员表单
function EditMemberForm($add,$userid,$username){
	global $empire,$dbtbpre;
	$fid=(int)$add['fid'];
	if(empty($add[fname])||!$fid)
	{
		printerror("EmptyMemberForm","history.go(-1)");
	}
	//验证权限
	CheckLevel($userid,$username,$classid,"memberf");
	$enter=TogMqenter($add['cname'],$add['center']);
	$viewenter=TogMqenter($add['cname'],$add['venter']);
	$mustenter=TogMustf($add['cname'],$add['menter']);
	$filef=ReturnMFileF($enter,$dbtbpre."enewsmemberf",0,"file");
	$imgf=ReturnMFileF($enter,$dbtbpre."enewsmemberf",0,"img");
	$tobrf=ReturnMFileF($enter,$dbtbpre."enewsmemberf",0,"textarea");
	//自动生成表单
	if($add[ftype])
	{
		$add[ftemp]=ReturnMemberFtemp($add['cname'],$add['center']);
	}
	$sql=$empire->query("update {$dbtbpre}enewsmemberform set fname='$add[fname]',ftemp='".addslashes($add[ftemp])."',fzs='".addslashes($add[fzs])."',enter='$enter',mustenter='$mustenter',filef='$filef',imgf='$imgf',tobrf='$tobrf',viewenter='$viewenter' where fid=$fid");
	//生成表单页面
	ChangeMemberForm($fid,$add[ftemp]);
	if($sql)
	{
	    insert_dolog("fid=".$fid."<br>fname=".$add[fname]);//操作日志
		printerror("EditMemberFormSuccess","member/ListMemberForm.php");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//删除会员表单
function DelMemberForm($add,$userid,$username){
	global $empire,$dbtbpre;
	$fid=(int)$add['fid'];
	if(!$fid)
	{
		printerror("EmptyMemberFormId","history.go(-1)");
	}
	//验证权限
	CheckLevel($userid,$username,$classid,"memberf");
	$r=$empire->fetch1("select fid,fname from {$dbtbpre}enewsmemberform where fid=$fid;");
	if(!$r['fid'])
	{
		printerror("EmptyMemberFormId","history.go(-1)");
	}
	$sql=$empire->query("delete from {$dbtbpre}enewsmemberform where fid=$fid;");
	//删除表单文件
	$file="../data/html/memberform".$fid.".php";
	DelFiletext($file);
	if($sql)
	{
	    insert_dolog("fid=".$fid."<br>fname=".$r[fname]);//操作日志
		printerror("DelMemberFormSuccess","member/ListMemberForm.php");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//增加投票
function AddInfoVote($classid,$id,$add){
	global $empire,$dbtbpre,$class_r;
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsinfovote where id='$id' and classid='$classid'");
	$votename=$add['vote_name'];
	$votenum=$add['vote_num'];
	//统计总票数
	for($i=0;$i<count($votename);$i++)
	{
		$t_votenum+=$votenum[$i];
	}
	$t_votenum=(int)$t_votenum;
	$voteclass=(int)$add['vote_class'];
	$width=(int)$add['vote_width'];
	$height=(int)$add['vote_height'];
	$doip=(int)$add['dovote_ip'];
	$tempid=(int)$add['vote_tempid'];
	if($num)	//修改
	{
		$votetext=ReturnVote($add['vote_name'],$add['vote_num'],$add['delvote_id'],$add['vote_id'],1);	//返回组合
		$sql=$empire->query("update {$dbtbpre}enewsinfovote set title='$add[vote_title]',votetext='$votetext',voteclass=$voteclass,doip=$doip,dotime='$add[vote_dotime]',tempid=$tempid,width=$width,height=$height where id='$id' and classid='$classid' limit 1");
	}
	else	//增加
	{
		$votetext=ReturnVote($add['vote_name'],$add['vote_num'],$add['delvote_id'],$add['vote_id'],0);	//返回组合
		if(empty($votetext))
		{
			return '';
		}
		$sql=$empire->query("insert into {$dbtbpre}enewsinfovote(id,classid,title,voteip,votetext,voteclass,doip,dotime,tempid,width,height) values('$id','$classid','$add[vote_title]','','$votetext',$voteclass,$doip,'$add[vote_dotime]',$tempid,$width,$height);");
	}
	$usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set votenum=$t_votenum where id='$id'");
}

//增加信息处理变量
function DoPostInfoVar($add){
	//组合标题属性
	$add[titlecolor]=RepPhpAspJspcodeText($add[titlecolor]);
	$add['my_titlefont']=TitleFont($add[titlefont],$add[titlecolor]);
	//文件前缀
	$add[filenameqz]=RepFilenameQz($add[filenameqz]);
	//组合专题ID
	$add['my_ztid']=ZtId($add[ztid]);
	//其它变量
	$add[keyboard]=RepPhpAspJspcodeText($add[keyboard]);
	$add[titleurl]=RepPhpAspJspcodeText($add[titleurl]);
	$add[checked]=(int)$add[checked];
	$add[istop]=(int)$add[istop];
	$add[dokey]=(int)$add[dokey];
	$add[isgood]=(int)$add[isgood];
	$add[fh]=(int)$add[fh];
	$add[groupid]=(int)$add[groupid];
	$add[newstempid]=(int)$add[newstempid];
	$add[firsttitle]=(int)$add[firsttitle];
	$add[userfen]=(int)$add[userfen];
	$add[closepl]=(int)$add[closepl];
	return $add;
}

//增加信息
function AddNews($add,$userid,$username){
	global $empire,$class_r,$class_zr,$bclassid,$public_r,$dbtbpre;
	$add[classid]=(int)$add[classid];
	$userid=(int)$userid;
	$ztid=$add[ztid];
	if(!$add[title]||!$add[classid]||!$add[newstempid])
	{
		printerror("EmptyTitle","history.go(-1)");
	}
	//操作权限
	$doselfinfo=CheckLevel($userid,$username,$add[classid],"news");
	if(!$doselfinfo['doaddinfo'])//增加权限
	{
		printerror("NotAddInfoLevel","history.go(-1)");
	}
	$ccr=$empire->fetch1("select classid,modid,listdt,haddlist,sametitle,addreinfo,wburl from {$dbtbpre}enewsclass where classid='$add[classid]' and islast=1");
	if(!$ccr['classid']||$ccr[wburl])//检测ixia是否是终极目录或者是外部链接
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	if($ccr['sametitle'])//验证标题重复
	{
		$num=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where title='$add[title]' limit 1");
		if($num)
		{
			printerror("ReInfoTitle","history.go(-1)");
	    }
    }
	$add=DoPostInfoVar($add);//返回变量
	$ret_r=ReturnAddF($add,$class_r[$add[classid]][modid],$userid,$username,0,0,1);//返回自定义字段
	$newspath=FormatPath($add[classid],'',0);//查看目录是否存在，不存在则建立
	//签发
	$isqf=0;
	if($add[checkuser])
	{
		$checkuser=",".$add[checkuser].",";
		$add[checked]=0;
		$user=explode(",",$add[checkuser]);
		foreach($user as $a){
		  $userchecktime[$a]="<font color=red>X</font>";
		}
		$userchecktime=serialize($userchecktime);
		$isqf=1;
		$add[checked]=1;
		$ccr[addreinfo]=1;
	}
	$truetime=time();
	$lastdotime=$truetime;
	//返回关键字组合
	$keyid=GetKeyid($add[keyboard],$add[classid],0,$class_r[$add[classid]][link_num]);
	$sql=$empire->query("insert into {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]."(classid,onclick,newspath,keyboard,keyid,userid,username,ztid,checked,istop,truetime,ismember,dokey,isgood,titlefont,titleurl,filename,filenameqz,fh,groupid,newstempid,plnum,firsttitle,isqf,userfen,totaldown,closepl,havehtml,lastdotime,haveaddfen,infopfen,infopfennum,votenum".$ret_r[fields].") values($add[classid],0,'$newspath','".addslashes($add[keyboard])."','$keyid',$userid,'".addslashes($username)."','$add[my_ztid]',$add[checked],$add[istop],$truetime,0,$add[dokey],$add[isgood],'".addslashes($add[my_titlefont])."','".addslashes($add[titleurl])."','$filename','$add[filenameqz]',$add[fh],$add[groupid],$add[newstempid],0,$add[firsttitle],'$isqf',$add[userfen],0,$add[closepl],0,$lastdotime,0,0,0,0".$ret_r[values].");");
	$id=$empire->lastid();
	//签发
	if($isqf==1)
	{
		$iqfsql=$empire->query("insert into {$dbtbpre}enewsqf(id,classid,checkuser,docheckuser,viewcheckuser,returncheck,notdocheckuser,checked,userchecktime) values('$id','$add[classid]','".addslashes($checkuser)."',',',',',0,',',0,'".$userchecktime."');");
	}
	//更新附件表
	UpdateTheFile($id,$add['filepass']);
	//取第一张图作为标题图片
	if($add['getfirsttitlepic']&&empty($add['titlepic']))
	{
		$firsttitlepic=GetFpicToTpic($add['classid'],$id,$add['getfirsttitlepic'],$add['getfirsttitlespic'],$add['getfirsttitlespicw'],$add['getfirsttitlespich']);
		if($firsttitlepic)
		{
			$addtitlepic=",titlepic='".addslashes($firsttitlepic)."'";
		}
	}
	//文件命名
	if($add['diyfilename']==1&&$add['filename'])
	{
		$filename=$add['filename'];
	}
	else
	{
		$filename=ReturnInfoFilename($add[classid],$id,$add[filenameqz]);
	}
	$usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." set filename='$filename'".$addtitlepic." where id='$id'");
	//投票
	AddInfoVote($add['classid'],$id,$add);	echo  $crr['addreinfo'];
	//增加信息是否生成文件
	if($ccr['addreinfo'])
{
		$ar=$empire->fetch1("select * from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where id='$id'");
		GetHtml($ar,$ret_r);
	}
	if($ccr[haddlist]&&$add[checked])
	{
		hAddListHtml($add[classid],$ccr['modid'],$ccr['haddlist'],$ccr['listdt']);//生成信息列表
		//ListHtml($add[classid],$ret_r,0);
		for($z=0;$z<count($ztid);$z++)//生成专题列表
		{
			ListHtml($ztid[$z],$ret_r,1);
		}
	}
	if($sql)
	{
		insert_dolog("classid=$add[classid]<br>id=".$id."<br>title=".$add[title]);//操作日志
		printerror("AddNewsSuccess","AddNews.php?enews=AddNews&bclassid=$add[bclassid]&classid=$add[classid]");
	}
	else
	{
		printerror("DbError","");
	}
}

//修改信息
function EditNews($add,$userid,$username){
	global $empire,$class_r,$class_zr,$bclassid,$public_r,$dbtbpre;
	$add[classid]=(int)$add[classid];
	$userid=(int)$userid;
	$ztid=$add[ztid];
	$add[id]=(int)$add[id];
	if(!$add[id]||!$add[title]||!$add[classid]||!$add[filename]||!$add[newstempid])
	{
		printerror("EmptyTitle","history.go(-1)");
	}
	$doselfinfo=CheckLevel($userid,$username,$add[classid],"news");//操作权限
	if(!$doselfinfo['doeditinfo'])//编辑权限
	{
		printerror("NotEditInfoLevel","history.go(-1)");
	}
	$ccr=$empire->fetch1("select classid,modid,listdt,haddlist,sametitle,addreinfo,wburl from {$dbtbpre}enewsclass where classid='$add[classid]' and islast=1");
	if(!$ccr['classid']||$ccr[wburl])
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	$checkr=$empire->fetch1("select id,userid,username,ismember from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where id='$add[id]' and classid='$add[classid]'");
	if(!$checkr[id])
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	if($doselfinfo['doselfinfo']&&($checkr[userid]<>$userid||$checkr[ismember]))//只能编辑自己的信息
	{
		printerror("NotDoSelfinfo","history.go(-1)");
    }
	if($ccr['sametitle'])//验证标题重复
	{
		$num=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where title='$add[title]' and id<>$add[id] limit 1");
		if($num)
		{
			printerror("ReInfoTitle","history.go(-1)");
	    }
    }
	$add=DoPostInfoVar($add);//返回变量
	$ret_r=ReturnAddF($add,$class_r[$add[classid]][modid],$userid,$username,1,0,1);//返回自定义字段
	if(empty($add[oldgroupid])&&$add[groupid]<>$add[oldgroupid])//改变文件权限
	{
        DelNewsFile($add[filename],$add[newspath],$add[classid],$add[newstext],0);//删除旧的文件
	}
	//签发
	$a="";
	if(empty($add[oldchecked]))
	{
	  if($add[checkuser])
	  {
		$aqf=",isqf=1";
		$add[checked]=0;
		$checkuser=",".$add[checkuser].",";
		$a.="checkuser='".addslashes($checkuser)."'";
		if($add[oldcheckuser]<>$add[checkuser])
		{
			$a.=",viewcheckuser=',',docheckuser=',',returncheck=0,notdocheckuser=','";
			$checksql=$empire->query("delete from {$dbtbpre}enewschecktext where id='$add[id]' and classid='$add[classid]'");
		}
		else
		{
			//重新签发
			if($add[recheckuser]&&$add[oldcheckuser])
			{
				$a.=",returncheck=0";
				//去除退稿的用户与浏览状态
				if($add[oldnotdocheckuser]!=",")
				{
					$checkr=explode(",",$add[oldnotdocheckuser]);
					$viewcheckuser=$add[oldviewcheckuser];
					for($i=1;$i<count($checkr)-1;$i++)
					{
						$viewcheckuser=str_replace(",".$checkr[$i].",",",",$viewcheckuser);
					}
					$a.=",notdocheckuser=',',viewcheckuser='".addslashes($viewcheckuser)."'";
				}
				$checksql=$empire->query("update {$dbtbpre}enewschecktext set isold=1 where id='$add[id]' and classid='$add[classid]'");
			}
		}
		if($a)
		{
			$qfnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsqf where id='$add[id]' and classid='$add[classid]' limit 1");
			if($qfnum)
			{
				$uqfsql=$empire->query("update {$dbtbpre}enewsqf set ".$a." where id='$add[id]' and classid='$add[classid]'");
			}
			else
			{
				$iqfsql=$empire->query("insert into {$dbtbpre}enewsqf(id,classid,checkuser,docheckuser,viewcheckuser,returncheck,notdocheckuser,checked) values('$add[id]','$add[classid]','".addslashes($checkuser)."',',',',',0,',',0);");
			}
		}
	  }
	}
	//文件名
	if($add['diyfilename']==1&&$add['filename']&&$add['filename']!=$add['oldfilename'])
	{
		$newfilename=$add['filename'];
		$updatefile=",filename='$newfilename'";
		DelNewsFile($add[oldfilename],$add[newspath],$add[classid],$add[newstext],$add[oldgroupid]);//删除旧文件
	}
	else
	{
		if($add[oldfilenameqz]!=$add[filenameqz])//修改文件名前缀
		{
			if(empty($add[oldfilenameqz]))
			{
				$newfilename=$add[filenameqz].$add[oldfilename];
			}
			else
			{
				$newfilename=str_replace($add[oldfilenameqz],$add[filenameqz],$add[oldfilename]);
			}
			$updatefile=",filename='$newfilename',filenameqz='$add[filenameqz]'";
			DelNewsFile($add[oldfilename],$add[newspath],$add[classid],$add[newstext],$add[oldgroupid]);//删除旧文件
		}
	}
	$lastdotime=time();
	//返回关键字组合
	$keyid=GetKeyid($add[keyboard],$add[classid],$add[id],$class_r[$add[classid]][link_num]);
	//修改数据库
	$sql=$empire->query("update {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." set classid=$add[classid],newspath='$add[newspath]',keyboard='".addslashes($add[keyboard])."',keyid='$keyid',ztid='$add[my_ztid]',checked=$add[checked],istop=$add[istop],dokey=$add[dokey],isgood=$add[isgood],titlefont='".addslashes($add[my_titlefont])."',titleurl='".addslashes($add[titleurl])."',fh=$add[fh],groupid=$add[groupid],newstempid=$add[newstempid],firsttitle=$add[firsttitle],userfen=$add[userfen],closepl=$add[closepl],lastdotime=$lastdotime".$updatefile.$aqf.$ret_r[values]." where id='$add[id]'");
	//取第一张图作为标题图片
	if($add['getfirsttitlepic']&&empty($add['titlepic']))
	{
		$firsttitlepic=GetFpicToTpic($add['classid'],$add['id'],$add['getfirsttitlepic'],$add['getfirsttitlespic'],$add['getfirsttitlespicw'],$add['getfirsttitlespich']);
		if($firsttitlepic)
		{
			$usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." set titlepic='".addslashes($firsttitlepic)."' where id='$add[id]'");
		}
	}
	//更新附件
	UpdateTheFileEdit($add['classid'],$add['id']);
	//投票
	AddInfoVote($add['classid'],$add['id'],$add);
	//生成文件
	if($ccr['addreinfo'])
	{
		$ar=$empire->fetch1("select * from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where id='$add[id]'");
		GetHtml($ar,$ret_r);
	}
	if($ccr['haddlist']&&($add[checked]||$add[checked]<>$add[oldchecked]))
	{
		hAddListHtml($add[classid],$ccr['modid'],$ccr['haddlist'],$ccr['listdt']);//生成信息列表
		//ListHtml($add[classid],$ret_r,0);//生成列表
		for($z=0;$z<count($ztid);$z++)//生成专题列表
		{
			ListHtml($ztid[$z],$ret_r,1);
		}
		//改变专题
		$oldztid=$add[oldztid];
		$myztid=$add['my_ztid'];
		if($oldztid<>$myztid&&$oldztid)
		{
			$o_z=explode("|",$oldztid);
			for($z=1;$z<count($o_z)-1;$z++)
			{
				$cr=explode("|".$o_z[$z]."|",$myztid);
				if($cr==1)
				{
					ListHtml($o_z[$z],$ret_r,1);
				}
			}
       }
	}
	if($sql)
	{
		insert_dolog("classid=$add[classid]<br>id=".$add[id]."<br>title=".$add[title]);//操作日志
		printerror("EditNewsSuccess","ListNews.php?bclassid=$add[bclassid]&classid=$add[classid]");
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//删除信息
function DelNews($id,$classid,$userid,$username){
	global $empire,$class_r,$class_zr,$bclassid,$public_r,$dbtbpre;
	$id=(int)$id;
	$classid=(int)$classid;
	if(!$id||!$classid)
	{
		printerror("NotDelNewsid","history.go(-1)");
	}
	$doselfinfo=CheckLevel($userid,$username,$classid,"news");//操作权限
	if(!$doselfinfo['dodelinfo'])//删除权限
	{
		printerror("NotDelInfoLevel","history.go(-1)");
	}
	$ccr=$empire->fetch1("select classid,modid,listdt,haddlist from {$dbtbpre}enewsclass where classid='$classid'");
	if(!$ccr['classid'])
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	$r=$empire->fetch1("select * from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='$id' and classid='$classid'");
	if(!$r[classid])
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	if($doselfinfo['doselfinfo']&&($r[userid]<>$userid||$r[ismember]))//只能编辑自己的信息
	{
		printerror("NotDoSelfinfo","history.go(-1)");
    }
	$ret_r=ReturnAddF($add,$class_r[$classid][modid],$userid,$username,2,2,0);//返回自定义字段
	//存放文本
	if(strstr($public_r['savetxtf'],",".$class_r[$r[classid]][tbname].".newstext,"))
	{
		$newstextfile=$r[newstext];
		$r[newstext]=GetTxtFieldText($r[newstext]);
		DelTxtFieldText($newstextfile);//删除文件
	}
	DelNewsFile($r[filename],$r[newspath],$classid,$r[newstext],$r[groupid]);//删除信息文件
	$sql=$empire->query("delete from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='$id'");
	//删除其它表记录
	$delsql=$empire->query("delete from {$dbtbpre}enewsqf where id='$id' and classid='$r[classid]'");
	$delsql=$empire->query("delete from {$dbtbpre}enewsinfovote where id='$id' and classid='$r[classid]'");
	$delsql=$empire->query("delete from {$dbtbpre}enewsdiggips where id='$id' and classid='$r[classid]'");
	DelNewsTheFile($id,$classid);//删除附件
	if($r['checked'])
	{
		hAddListHtml($classid,$ccr['modid'],$ccr['haddlist'],$ccr['listdt']);//生成信息列表
		//ListHtml($classid,$ret_r,0);//生成列表
		if($r[ztid])//如果是专题
		{
			$z_r=explode("|".$r[ztid]."|",$r[ztid]);
			for($z=1;$z<count($z_r)-1;$z++)
			{
				ListHtml($z_r[$z],$ret_r,1);
			}
		}
	}
	if($sql)
	{
		insert_dolog("classid=$classid<br>id=".$id."<br>title=".$r[title]);//操作日志
		printerror("DelNewsSuccess",$_SERVER['HTTP_REFERER']);
	}
	else
	{
		printerror("ErrorUrl","history.go(-1)");
	}
}

//批量删除信息
function DelNews_all($id,$classid,$userid,$username,$ecms=0){
	global $empire,$class_r,$class_zr,$public_r,$dbtbpre;
	$count=count($id);
	if(!$count)
	{
		printerror("NotDelNewsid","history.go(-1)");
	}
	$doselfinfo=CheckLevel($userid,$username,$classid,"news");//操作权限
	if(!$doselfinfo['dodelinfo'])//删除权限
	{
		printerror("NotDelInfoLevel","history.go(-1)");
	}
	if($ecms==1)
	{
		$doctb="_doc";
	}
	for($i=0;$i<$count;$i++)
	{
		$add.="id='$id[$i]' or ";
    }
	$add=substr($add,0,strlen($add)-4);
	for($i=0;$i<$count;$i++)//删除信息文件
	{
		$r=$empire->fetch1("select * from {$dbtbpre}ecms_".$class_r[$classid][tbname].$doctb." where id='$id[$i]'");
		if($doselfinfo['doselfinfo']&&($r[userid]<>$userid||$r[ismember]))//只能编辑自己的信息
		{
			continue;
		}
		//存放文本
		if(strstr($public_r['savetxtf'],",".$class_r[$r[classid]][tbname].".newstext,"))
		{
			$newstextfile=$r[newstext];
			$r[newstext]=GetTxtFieldText($r[newstext]);
			DelTxtFieldText($newstextfile);//删除文件
		}
		DelNewsFile($r[filename],$r[newspath],$r[classid],$r[newstext],$r[groupid]);
		DelNewsTheFile($id[$i],$r[classid]);//删除附件
		//删除其它表记录
		$delsql=$empire->query("delete from {$dbtbpre}enewsqf where id='$id[$i]' and classid='$r[classid]'");
		$delsql=$empire->query("delete from {$dbtbpre}enewsinfovote where id='$id[$i]' and classid='$r[classid]'");
		$delsql=$empire->query("delete from {$dbtbpre}enewsdiggips where id='$id[$i]' and classid='$r[classid]'");
    }
	//删除信息
	$sql=$empire->query("delete from {$dbtbpre}ecms_".$class_r[$classid][tbname].$doctb." where ".$add);
	if(empty($doctb))
	{
		//$ret_r=ReturnAddF($add,$class_r[$r[classid]][modid],$userid,$username,2,2,0);//生成列表
		//ListHtml($r[classid],$ret_r,0);
		$ccr=$empire->fetch1("select classid,modid,listdt,haddlist from {$dbtbpre}enewsclass where classid='$classid'");
		hAddListHtml($classid,$ccr['modid'],$ccr['haddlist'],$ccr['listdt']);//生成信息列表
	}
	if($sql)
	{
		insert_dolog("classid=".$classid."<br>classname=".$class_r[$classid][classname]);//操作日志
		printerror("DelNewsAllSuccess",$_SERVER['HTTP_REFERER']);
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//删除文件
function DelFile($fileid,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	$fileid=(int)$fileid;
	if(!$fileid)
	{printerror("NotFileid","history.go(-1)");}
	//操作权限
	CheckLevel($userid,$username,$classid,"file");
	$r=$empire->fetch1("select filename,path,classid,fpath from {$dbtbpre}enewsfile where fileid='$fileid' limit 1");
	$sql=$empire->query("delete from {$dbtbpre}enewsfile where fileid='$fileid'");
	DoDelFile($r);
	if($sql)
	{
		//操作日志
		insert_dolog("fileid=".$fileid."<br>filename=".$r[filename]);
		printerror("DelFileSuccess",$_SERVER['HTTP_REFERER']);
    }
	else
	{
		printerror("DbError","history.go(-1)");
    }
}

//刷新页面
function AddInfoToReHtml($classid,$dore){
	global $class_r;
	hAddListHtml($classid,$class_r[$classid]['modid'],$dore,$class_r[$classid]['listdt']);//生成信息列表
	insert_dolog("classid=".$classid."<br>do=".$dore);//操作日志
	printerror('AddInfoToReHtmlSuccess','history.go(-1)');
}

//增加信息生成页面
function hAddListHtml($classid,$mid,$qaddlist,$listdt){
	global $class_r;
	if($qaddlist==0)//不生成
	{
		return "";
	}
	elseif($qaddlist==1)//生成当前栏目
	{
		if(!$listdt)
		{
			$sonclass="|".$classid."|";
			hReClassHtml($sonclass);
		}
	}
	elseif($qaddlist==2)//生成首页
	{
		hReIndex();
	}
	elseif($qaddlist==3)//生成父栏目
	{
		$featherclass=$class_r[$classid]['featherclass'];
		if($featherclass&&$featherclass!="|")
		{
			hReClassHtml($featherclass);
		}
	}
	elseif($qaddlist==4)//生成当前栏目与父栏目
	{
		$featherclass=$class_r[$classid]['featherclass'];
		if(empty($featherclass))
		{
			$featherclass="|";
		}
		if(!$listdt)
		{
			$featherclass.=$classid."|";
		}
		hReClassHtml($featherclass);
	}
	elseif($qaddlist==5)//生成父栏目与首页
	{
		hReIndex();
		$featherclass=$class_r[$classid]['featherclass'];
		if($featherclass&&$featherclass!="|")
		{
			hReClassHtml($featherclass);
		}
	}
	elseif($qaddlist==6)//生成当前栏目、父栏目与首页
	{
		hReIndex();
		$featherclass=$class_r[$classid]['featherclass'];
		if(empty($featherclass))
		{
			$featherclass="|";
		}
		if(!$listdt)
		{
			$featherclass.=$classid."|";
		}
		hReClassHtml($featherclass);
	}
}

//投稿生成栏目
function hReClassHtml($sonclass){
	global $empire,$dbtbpre,$class_r;
	$r=explode("|",$sonclass);
	$count=count($r);
	for($i=1;$i<$count-1;$i++)
	{
		//终极栏目
		if($class_r[$r[$i]]['islast'])
		{
			if(!$class_r[$r[$i]]['listdt'])
			{
				$ret_r=ReturnAddF($r,$class_r[$r[$i]]['modid'],$userid,$username,2,2,0);
				ListHtml($r[$i],$ret_r,0,$userlistr);
			}
		}
		elseif($class_r[$r[$i]]['islist'])//列表式父栏目
		{
			if(!$class_r[$r[$i]]['listdt'])
			{
				$ret_r=ReturnAddF($r,$class_r[$r[$i]]['modid'],$userid,$username,2,2,0);
				ListHtml($r[$i],$ret_r,3);
			}
		}
		else//父栏目
		{
			$cr=$empire->fetch1("select classtempid from {$dbtbpre}enewsclass where classid='$r[$i]'");
			NewsBq($r[$i],GetClassTemp($cr['classtempid']),0,0);
		}
	}
}

//投稿生成首页
function hReIndex(){
	$indextemp=GetIndextemp();
	NewsBq($classid,$indextemp,1,0);
}

//批量删除文件
function DelFile_all($fileid,$userid,$username){
	global $empire,$dbtbpre,$class_r;
	//操作权限
	if($_POST['enews']=='TDelFile_all')
	{
		$ur=$empire->fetch1("select groupid,adminclass,filelevel from {$dbtbpre}enewsuser where userid='$userid' limit 1");
		if($ur['filelevel'])
		{
			$gr=$empire->fetch1("select dofile from {$dbtbpre}enewsgroup where groupid='$ur[groupid]'");
			if(!$gr['dofile'])
			{
				$classid=(int)$_POST['classid'];
				$searchclassid=(int)$_POST['searchclassid'];
				$classid=$searchclassid?$searchclassid:$classid;
				if(!$class_r[$classid]['classid'])
				{
					printerror("NotLevel","history.go(-1)");
				}
				if(!strstr($ur['adminclass'],'|'.$classid.'|'))
				{
					printerror("NotLevel","history.go(-1)");
				}
			}
		}
		else
		{
			CheckLevel($userid,$username,$classid,"file");
		}
	}
	else
	{
		CheckLevel($userid,$username,$classid,"file");
	}
	$count=count($fileid);
	if(!$count)
	{printerror("NotFileid","history.go(-1)");}
	for($i=0;$i<count($fileid);$i++)
	{
       $r=$empire->fetch1("select filename,path,classid,fpath from {$dbtbpre}enewsfile where fileid='$fileid[$i]' limit 1");
       $sql=$empire->query("delete from {$dbtbpre}enewsfile where fileid='$fileid[$i]'");
       DoDelFile($r);
    }
	if($sql)
	{
		//操作日志
		insert_dolog("");
		printerror("DelFileAllSuccess",$_SERVER['HTTP_REFERER']);
    }
	else
	{
		printerror("DbError","history.go(-1)");
    }
}

//删除多余附件
function DelFreeFile($userid,$username){
	global $empire,$dbtbpre;
	//操作权限
	CheckLevel($userid,$username,$classid,"file");
	$sql=$empire->query("select filename,path,classid,fpath from {$dbtbpre}enewsfile where cjid<>0 and (id=0 or cjid=id)");
	while($r=$empire->fetch($sql))
	{
       DoDelFile($r);
    }
	$delsql=$empire->query("delete from {$dbtbpre}enewsfile where cjid<>0 and (id=0 or cjid=id)");
	if($sql)
	{
		//操作日志
		insert_dolog("");
		printerror("DelFreeFileSuccess",$_SERVER['HTTP_REFERER']);
    }
	else
	{
		printerror("DbError","history.go(-1)");
    }
}

//信息置顶
function TopNews_all($classid,$id,$istop,$userid,$username){
	global $empire,$bclassid,$class_r,$dbtbpre;
	if(empty($classid))
	{printerror("ErrorUrl","history.go(-1)");}
	$doselfinfo=CheckLevel($userid,$username,$classid,"news");//验证权限
	if(!$doselfinfo['doeditinfo'])//编辑权限
	{
		printerror("NotEditInfoLevel","history.go(-1)");
	}
	$count=count($id);
	if(empty($count))
	{printerror("NotTopNewsid","history.go(-1)");}
	for($i=0;$i<$count;$i++)
	{
		$add.="id='$id[$i]' or ";
	}
	$istop=(int)$istop;
	$add=substr($add,0,strlen($add)-4);
	$sql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set istop=$istop where ".$add);
	//刷新列表
	ReListHtml($classid,1);
	if($sql)
	{
		insert_dolog("classid=".$classid."<br>classname=".$class_r[$classid][classname]);//操作日志
		printerror("TopNewsSuccess",$_SERVER['HTTP_REFERER']);
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//审核信息
function CheckNews_all($classid,$id,$userid,$username,$qf=true){//增加一个参数$qf是保证全部签发文件后生成这个文件的html并通过审核 默认通过审核
	global $empire,$class_r,$dbtbpre;
	if(empty($classid))
	{printerror("ErrorUrl","history.go(-1)");}
	//验证权限
	$doselfinfo=CheckLevel($userid,$username,$classid,"news");
	//编辑权限
	if(!$doselfinfo['doeditinfo'])
	{
		printerror("NotEditInfoLevel","history.go(-1)");
	}
	$count=count($id);
	if(empty($count))
	{printerror("NotCheckNewsid","history.go(-1)");}
	if(is_array($id)){//这里的判断是为了让签发文件在全部签发后自动审核并生成html
    for($i=0;$i<$count;$i++)
    {
      $add.="id='$id[$i]' or ";
    }
    $add=substr($add,0,strlen($add)-4);
  }
  else
      $add.="id=".$id;
  if($qf)//判断是否为处理签发信息过程中自动审核
      $add.=" and isqf=1";
  else
      $add.=" and isqf=0";
	$sql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set checked=1 where ".$add);
	$sql=$empire->query("select * from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where ".$add);
	while($r=$empire->fetch($sql))
	{
		//投稿增加积分
		if($r[ismember]&&$r[userid]&&!$r[haveaddfen])
		{
			$cr=$empire->fetch1("select classid,addinfofen from {$dbtbpre}enewsclass where classid='$r[classid]'");
			if($cr[addinfofen])
			{
				AddInfoFen($cr[addinfofen],$r[userid]);
				if($cr[addinfofen]<0)
				{
					BakDown($r[classid],$r[id],0,$r[userid],$r[username],$r[title],abs($cr[addinfofen]),3);
				}
			}
			$usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set haveaddfen=1 where id=$r[id]");
		}
		//返回自定义字段
		$ret_r=ReturnAddF($r,$class_r[$r[classid]][modid],$userid,$username,2,1,0);
		//刷新信息
		GetHtml($r,$ret_r);
	}
	//刷新列表
	//ReListHtml($classid,1);
	if($sql)
	{
		//操作日志
		insert_dolog("classid=".$classid."<br>classname=".$class_r[$classid][classname]);
				printerror("CheckNewsSuccess",$_SERVER['HTTP_REFERER']);
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//取消审核信息
function NoCheckNews_all($classid,$id,$userid,$username){
	global $empire,$class_r,$public_r,$dbtbpre;
	if(empty($classid))
	{printerror("ErrorUrl","history.go(-1)");}
	//验证权限
	$doselfinfo=CheckLevel($userid,$username,$classid,"news");
	//编辑权限
	if(!$doselfinfo['doeditinfo'])
	{
		printerror("NotEditInfoLevel","history.go(-1)");
	}
	$count=count($id);
	if(empty($count))
	{printerror("NotNoCheckNewsid","history.go(-1)");}
	for($i=0;$i<$count;$i++)
	{
		//删除审核文件
		$r=$empire->fetch1("select * from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='".$id[$i]."'");
		//存放文本
		if(strstr($public_r['savetxtf'],",".$class_r[$r[classid]][tbname].".newstext,"))
		{
			$newstext_url=$r[newstext];
			$r[newstext]=GetTxtFieldText($r[newstext]);
		}
		DelNewsFile($r[filename],$r[newspath],$r[classid],$r[newstext],$r[groupid]);
		$add.="id='$id[$i]' or ";
	}
	$add=substr($add,0,strlen($add)-4);
	$sql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set checked=0,havehtml=0 where isqf=0 and (".$add.")");
	//刷新列表
	ReListHtml($classid,1);
	if($sql)
	{
		//操作日志
		insert_dolog("classid=".$classid."<br>classname=".$class_r[$classid][classname]);
		printerror("NoCheckNewsSuccess",$_SERVER['HTTP_REFERER']);
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//移动信息
function MoveNews_all($classid,$id,$to_classid,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	if(empty($classid)||empty($to_classid))
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	if(empty($class_r[$classid][islast])||empty($class_r[$to_classid][islast]))
	{
		printerror("EmptyMoveClassid","history.go(-1)");
	}
	if($class_r[$classid][modid]<>$class_r[$to_classid][modid])
	{
		printerror("DefModid","history.go(-1)");
    }
	//验证权限
	$doselfinfo=CheckLevel($userid,$username,$classid,"news");
	//编辑权限
	if(!$doselfinfo['doeditinfo'])
	{
		printerror("NotEditInfoLevel","history.go(-1)");
	}
	$count=count($id);
	if(empty($count))
	{printerror("NotMoveNewsid","history.go(-1)");}
	for($i=0;$i<$count;$i++)
	{
		$add.="id='$id[$i]' or ";
	}
	$to_classid=(int)$to_classid;
	$add=substr($add,0,strlen($add)-4);
	$sql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set classid=$to_classid where ".$add);
	//评论转换
	$uplsql=$empire->query("update {$dbtbpre}enewspl set classid=$to_classid where (".$add.") and classid='$classid'");
	//签发转换
	$uqfsql=$empire->query("update {$dbtbpre}enewsqf set classid=$to_classid where (".$add.") and classid='$classid'");
	//投票
	$uvotesql=$empire->query("update {$dbtbpre}enewsinfovote set classid=$to_classid where (".$add.") and classid='$classid'");
	//刷新列表
	ReListHtml($classid,1);
	ReListHtml($to_classid,1);
	if($sql)
	{
		//操作日志
		insert_dolog("classid=".$classid."<br>classname=".$class_r[$classid][classname]);
		printerror("MoveNewsSuccess",$_SERVER['HTTP_REFERER']);
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//复制信息
function CopyNews_all($classid,$id,$to_classid,$userid,$username){
	global $empire,$public_r,$class_r,$dbtbpre;
	if(empty($classid)||empty($to_classid))
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	if(empty($class_r[$classid][islast])||empty($class_r[$to_classid][islast]))
	{
		printerror("EmptyCopyClassid","history.go(-1)");
	}
	if($class_r[$classid][modid]<>$class_r[$to_classid][modid])
	{
		printerror("DefModid","history.go(-1)");
    }
	$userid=(int)$userid;
	//验证权限
	$doselfinfo=CheckLevel($userid,$username,$classid,"news");
	//编辑权限
	if(!$doselfinfo['doeditinfo'])
	{
		printerror("NotEditInfoLevel","history.go(-1)");
	}
	$count=count($id);
	if(empty($count))
	{printerror("NotCopyNewsid","history.go(-1)");}
	for($i=0;$i<$count;$i++)
	{
		$add.="id='$id[$i]' or ";
    }
	$add=substr($add,0,strlen($add)-4);
	$to_classid=(int)$to_classid;
	//查看目录是否存在，不存在则建立
	$newspath=FormatPath($to_classid,"",0);
    $newstime=date("Y-m-d H:i:s");
    $truetime=time();
	$dosql=$empire->query("select * from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where ".$add);
	while($r=$empire->fetch($dosql))
	{
		//存放文本
		if(strstr($public_r['savetxtf'],",".$class_r[$classid][tbname].".newstext,"))
		{
			$r['newstext']=GetTxtFieldText($r['newstext']);
		}
		//返回自定义字段
		$ret_r=ReturnAddF($r,$class_r[$to_classid][modid],$userid,$username,9,1,0);
		if($class_r[$to_classid][docheckuser]&&$class_r[$to_classid][checkuser])
		{
			$checked=0;
			$checkuser=",".$class_r[$to_classid][checkuser].",";
			$isqf=1;
	    }
		else
		{
			$checked=$class_r[$to_classid][checked];
			$checkuser="";
			$isqf=0;
	    }
		$checked=(int)$checked;
		$sql=$empire->query("insert into {$dbtbpre}ecms_".$class_r[$to_classid][tbname]."(classid,onclick,newspath,keyboard,keyid,userid,username,ztid,checked,istop,truetime,ismember,dokey,isgood,titlefont,titleurl,filename,filenameqz,fh,groupid,newstempid,plnum,firsttitle,isqf,userfen,totaldown,closepl,havehtml,lastdotime,haveaddfen,infopfen,infopfennum,votenum".$ret_r[fields].") values($to_classid,0,'$newspath','$r[keyboard]','$r[keyid]',$userid,'$username','',$checked,0,$truetime,0,$r[dokey],0,'$r[titlefont]','$r[titleurl]','$filename','$r[filenameqz]',$r[fh],$r[groupid],".$class_r[$to_classid][newstempid].",0,0,'$isqf',$r[userfen],0,$r[closepl],$r[havehtml],$truetime,0,0,0,0".$ret_r[values].");");
		$l_id=$empire->lastid();
		//签发
		if($isqf==1)
		{
			$iqfsql=$empire->query("insert into {$dbtbpre}enewsqf(id,classid,checkuser,docheckuser,viewcheckuser,returncheck,notdocheckuser,checked) values('$l_id','$to_classid','".addslashes($checkuser)."',',',',',0,',',0);");
		}
		//文件命名
		$filename=ReturnInfoFilename($to_classid,$l_id,$r[filenameqz]);
		$usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$to_classid][tbname]." set filename='$filename' where id='$l_id'");
		//生成信息文件
		$addr=$empire->fetch1("select * from {$dbtbpre}ecms_".$class_r[$to_classid][tbname]." where id='$l_id'");
		GetHtml($addr,$ret_r);
	}
	//刷新列表
	ReListHtml($to_classid,1);
	//操作日志
	insert_dolog("classid=".$classid."<br>classname=".$class_r[$classid][classname]);
	printerror("CopyNewsSuccess",$_SERVER['HTTP_REFERER']);
}

//批量删除评论
function DelPl_all($plid,$id,$bclassid,$classid,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	//验证权限
	//CheckLevel($userid,$username,$classid,"news");
	$count=count($plid);
	if(empty($count))
	{
		printerror("NotDelPlid","history.go(-1)");
	}
	for($i=0;$i<$count;$i++)
	{
		$add.="plid='$plid[$i]' or ";
	}
	$add=substr($add,0,strlen($add)-4);
	//更新数据表
	$fsql=$empire->query("select id,classid from {$dbtbpre}enewspl where ".$add);
	while($r=$empire->fetch($fsql))
	{
		if($class_r[$r[classid]][tbname])
		{
			$usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$r[classid]][tbname]." set plnum=plnum-1 where id='$r[id]'");
		}
    }
	$sql=$empire->query("delete from {$dbtbpre}enewspl where ".$add);
	if($sql)
	{
		//操作日志
		insert_dolog("classid=".$classid."<br>classname=".$class_r[$classid][classname]);
		printerror("DelPlSuccess",$_SERVER['HTTP_REFERER']);
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//批量审核评论
function CheckPl_all($plid,$id,$bclassid,$classid,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	//验证权限
	//CheckLevel($userid,$username,$classid,"news");
	$count=count($plid);
	if(empty($count))
	{printerror("NotCheckPlid","history.go(-1)");}
	for($i=0;$i<$count;$i++)
	{
		$add.="plid='$plid[$i]' or ";
	}
	$add=substr($add,0,strlen($add)-4);
	$sql=$empire->query("update {$dbtbpre}enewspl set checked=0 where ".$add);
	if($sql)
	{
		//操作日志
		insert_dolog("classid=".$classid."<br>classname=".$class_r[$classid][classname]);
		printerror("CheckPlSuccess",$_SERVER['HTTP_REFERER']);
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//批量推荐/取消评论
function DoGoodPl_all($plid,$id,$bclassid,$classid,$isgood,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	//验证权限
	//CheckLevel($userid,$username,$classid,"news");
	$count=count($plid);
	if(empty($count))
	{
		printerror("NotGoodPlid","history.go(-1)");
	}
	$isgood=(int)$isgood;
	for($i=0;$i<$count;$i++)
	{
		$add.="plid='$plid[$i]' or ";
	}
	$add=substr($add,0,strlen($add)-4);
	$sql=$empire->query("update {$dbtbpre}enewspl set isgood=$isgood where ".$add);
	if($sql)
	{
		//操作日志
		insert_dolog("isgood=$isgood<br>classid=".$classid."<br>classname=".$class_r[$classid][classname]);
		printerror("DoGoodPlSuccess",$_SERVER['HTTP_REFERER']);
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改评论列表模板
function EditPltemp($temptext,$userid,$username){
	global $empire,$dbtbpre,$public_r;
	if(!$temptext)
	{printerror("EmptyTemptext","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set pllisttemp='".addslashes($temptext)."' limit 1");
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		GetSearchResult();
	}
	if($sql)
	{
		//操作日志
		insert_dolog("gid=$gid");
		printerror("EditPltempSuccess","template/EditPublicTemp.php?tname=pltemp&gid=$gid#pltemp");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改留言板模板
function EditGbooktemp($temptext,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	if(!$temptext)
	{printerror("EmptyTemptext","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set gbooktemp='".addslashes($temptext)."' limit 1");
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		ReGbooktemp();
	}
	if($sql)
	{
		//操作日志
		insert_dolog("gid=$gid");
		printerror("EditGbooktempSuccess","template/EditPublicTemp.php?tname=gbooktemp&gid=$gid#gbooktemp");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改控制面板模板
function EditCptemp($temptext,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	if(!$temptext)
	{printerror("EmptyTemptext","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set cptemp='".addslashes($temptext)."' limit 1");
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		ReCptemp();
	}
	if($sql)
	{
		//操作日志
		insert_dolog("gid=$gid");
		printerror("EditCptempSuccess","template/EditPublicTemp.php?tname=cptemp&gid=$gid#cptemp");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改登陆状态模板
function EditLoginIframe($temptext,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	if(!$temptext)
	{printerror("EmptyTemptext","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set loginiframe='".addslashes($temptext)."' limit 1");
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		ReLoginIframe();
	}
	if($sql)
	{
		//操作日志
		insert_dolog("gid=$gid");
		printerror("EditLoginIframeSuccess","template/EditPublicTemp.php?tname=loginiframe&gid=$gid#loginiframe");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改JS调用登陆状态模板
function EditLoginJstemp($temptext,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	if(!$temptext)
	{printerror("EmptyTemptext","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set loginjstemp='".addslashes($temptext)."' limit 1");
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		ReLoginIframe();
	}
	if($sql)
	{
		//操作日志
		insert_dolog("gid=$gid");
		printerror("EditLoginJstempSuccess","template/EditPublicTemp.php?tname=loginjstemp&gid=$gid#loginjstemp");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//增加会员组
function AddMemberGroup($add,$userid,$username){
	global $empire,$dbtbpre;
	if(empty($add[groupname])||empty($add[level]))
	{printerror("EmptyMemberGroupname","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"member");
	//处理文件
	$add[level]=(int)$add[level];
	$add[checked]=(int)$add[checked];
	$add[favanum]=(int)$add[favanum];
	$add[daydown]=(int)$add[daydown];
	$msgnum=(int)$add['msgnum'];
	$msglen=(int)$add['msglen'];
	$canreg=(int)$add['canreg'];
	$formid=(int)$add['formid'];
	$regchecked=(int)$add['regchecked'];
	$spacestyleid=(int)$add['spacestyleid'];
	$sql=$empire->query("insert into {$dbtbpre}enewsmembergroup(groupname,level,checked,favanum,daydown,msglen,msgnum,canreg,formid,regchecked,spacestyleid) values('$add[groupname]',$add[level],$add[checked],$add[favanum],$add[daydown],$msglen,$msgnum,$canreg,$formid,$regchecked,$spacestyleid);");
	$groupid=$empire->lastid();
	//更新缓存
	GetMemberLevel();
	if($sql)
	{
		//操作日志
		insert_dolog("groupid=".$groupid."<br>groupname=".$add[groupname]);
		printerror("AddMemberGroupSuccess","member/AddMemberGroup.php?enews=AddMemberGroup");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改会员组
function EditMemberGroup($add,$userid,$username){
	global $empire,$dbtbpre;
	$add[groupid]=(int)$add[groupid];
	if(empty($add[groupid])||empty($add[groupname])||empty($add[level]))
	{printerror("EmptyMemberGroupname","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"member");
	//处理文件
	$add[level]=(int)$add[level];
	$add[checked]=(int)$add[checked];
	$add[favanum]=(int)$add[favanum];
	$add[daydown]=(int)$add[daydown];
	$msgnum=(int)$add['msgnum'];
	$msglen=(int)$add['msglen'];
	$canreg=(int)$add['canreg'];
	$formid=(int)$add['formid'];
	$regchecked=(int)$add['regchecked'];
	$spacestyleid=(int)$add['spacestyleid'];
	$sql=$empire->query("update {$dbtbpre}enewsmembergroup set groupname='$add[groupname]',level=$add[level],checked=$add[checked],favanum=$add[favanum],daydown=$add[daydown],msglen=$msglen,msgnum=$msgnum,canreg=$canreg,formid=$formid,regchecked=$regchecked,spacestyleid=$spacestyleid where groupid='$add[groupid]'");
	//更新缓存
	GetMemberLevel();
	if($sql)
	{
		//操作日志
		insert_dolog("groupid=".$add[groupid]."<br>groupname=".$add[groupname]);
		printerror("EditMemberGroupSuccess","member/ListMemberGroup.php");
    }
	else
	{printerror("DbError","history.go(-1)");}
}

//删除会员组
function DelMemberGroup($groupid,$userid,$username){
	global $empire,$dbtbpre;
	$groupid=(int)$groupid;
	if(empty($groupid))
	{printerror("NotDelMemberGroupid","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"member");
	$r=$empire->fetch1("select groupname from {$dbtbpre}enewsmembergroup where groupid='$groupid'");
	$sql=$empire->query("delete from {$dbtbpre}enewsmembergroup where groupid='$groupid'");
	//更新缓存
	GetMemberLevel();
	if($sql)
	{
		//操作日志
		insert_dolog("groupid=".$groupid."<br>groupname=".$r[groupname]);
		printerror("DelMemberGroupSuccess","member/ListMemberGroup.php");
    }
	else
	{printerror("DbError","history.go(-1)");}
}

//修改采集信息
function EditCjNews($add,$newstext,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	$add[classid]=(int)$add[classid];
	$add[id]=(int)$add[id];
	if(empty($add[classid])||empty($add[id])||empty($add[title]))
	{printerror("EmptyCjTitle","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"cj");
	//取得采集字段
	$record="<!--record-->";
	$field="<!--field--->";
	$cr=$empire->fetch1("select newsclassid,tbname from {$dbtbpre}enewsinfoclass where classid='$add[classid]'");
	$r=$empire->fetch1("select cj from {$dbtbpre}enewsmod where mid='".$class_r[$cr[newsclassid]][modid]."'");
	$cjr=explode($record,$r[cj]);
	$count=count($cjr);
	$update="";
	for($i=0;$i<$count-1;$i++)
	{
		$cjr1=explode($field,$cjr[$i]);
		$dofield=$cjr1[1];
		//图片集
		if($dofield=="morepic")
		{
			$add[$dofield]=ReturnMorepicpath($add['msmallpic'],$add['mbigpic'],$add['mpicname'],$add['mdelpicid'],$add['mpicid'],$add,$add['mpicurl_qz'],1);
		}
		//下载地址
		if($dofield=="downpath")
		{
			$add[$dofield]=ReturnDownpath($add['downname'],$add['downpath'],$add['delpathid'],$add['pathid'],$add['downuser'],$add['fen'],$add['thedownqz'],$add,$add['foruser'],$add['downurl'],0);
		}
		//在线地址
		if($dofield=="onlinepath")
		{
			$add[$dofield]=ReturnDownpath($add['odownname'],$add['odownpath'],$add['odelpathid'],$add['opathid'],$add['odownuser'],$add['ofen'],$add['othedownqz'],$add,$add['oforuser'],$add['onlineurl_qz'],1);
		}
		//发布时间
		if($dofield=="newstime")
		{continue;}
		$update.=",".$dofield."='".addslashes($add[$dofield])."'";
	}
	$sql=$empire->query("update {$dbtbpre}ecms_infotmp_".$cr[tbname]." set keyboard='".addslashes($add[keyboard])."',newstime='$add[newstime]'".$update." where id='$add[id]'");
	if($sql)
	{
		//操作日志
		insert_dolog("id=".$add[id]."<br>title=".$add[title]);
		printerror("EditCjNewsSuccess","CheckCj.php?classid=$add[classid]&from=$_POST[from]");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//删除采集信息
function DelCjNews($classid,$id,$userid,$username){
	global $empire,$dbtbpre;
	$classid=(int)$classid;
	$id=(int)$id;
	if(empty($classid)||empty($id))
	{printerror("NotDelCjNewsid","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"cj");
	$cr=$empire->fetch1("select newsclassid,tbname from {$dbtbpre}enewsinfoclass where classid='$classid'");
	$r=$empire->fetch1("select title from {$dbtbpre}ecms_infotmp_".$cr[tbname]." where id='$id'");
	$sql=$empire->query("delete from {$dbtbpre}ecms_infotmp_".$cr[tbname]." where id='$id'");
	if($sql)
	{
		//操作日志
		insert_dolog("id=".$id."<br>title=".$r[title]);
		printerror("DelCjNewsSuccess","CheckCj.php?classid=$classid&from=$_GET[from]");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//批量删除采集信息
function DelCjNews_all($classid,$id,$userid,$username){
	global $empire,$dbtbpre;
	//操作权限
	CheckLevel($userid,$username,$classid,"cj");
	$count=count($id);
	if(!$count)
	{printerror("NotDelCjNewsid","history.go(-1)");}
	$cr=$empire->fetch1("select newsclassid,tbname,classname from {$dbtbpre}enewsinfoclass where classid='$classid'");
	for($i=0;$i<count($id);$i++)
	{
		$add.="id='".$id[$i]."' or ";
    }
	//去掉最后一个 or
	$add=substr($add,0,strlen($add)-4);
	$sql=$empire->query("delete from {$dbtbpre}ecms_infotmp_".$cr[tbname]." where ".$add);
	if($sql)
	{
		//操作日志
	    insert_dolog("classid=".$classid."<br>classname=".$cr[classname]);
		printerror("DelCjNewsAllSuccess",$_SERVER['HTTP_REFERER']);
    }
	else
	{
		printerror("DbError","history.go(-1)");
    }
}

//清除简介字符
function DoClearSmalltextVal($value){
	$value=str_replace(array("\r\n","<br />","<br>","&nbsp;","[!--empirenews.page--]","[/!--empirenews.page--]"),array("","\r\n","\r\n"," ","",""),$value);
	$value=strip_tags($value);
	$value=trim($value,"\r\n");
	return $value;
}

//采集入库
function CjNewsIn($classid,$id,$checked,$userid,$username){
	global $class_r,$empire,$public_r,$dbtbpre;
	$checked=(int)$checked;
	$classid=(int)$classid;
	if(empty($classid))
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	CheckLevel($userid,$username,$classid,"cj");//操作权限
	$count=count($id);
	if(empty($count))
	{
		printerror("NotCjNewsIn","history.go(-1)");
	}
	$cr=$empire->fetch1("select * from {$dbtbpre}enewsinfoclass where classid='$classid'");
	//副表
	$cra=$empire->fetch1("select * from {$dbtbpre}ecms_infoclass_".$cr[tbname]." where classid='$classid'");
	//组合两数组
    $cr=TogTwoArray($cr,$cra);
	//导入gd处理文件
	if($cr['mark']||$cr['getfirstspic'])
	{
		@include("gd.php");
	}
	//取得采集字段
	$record="<!--record-->";
	$field="<!--field--->";
	$mr=$empire->fetch1("select cj from {$dbtbpre}enewsmod where mid='".$class_r[$cr[newsclassid]][modid]."'");
	$cjr=explode($record,$mr[cj]);
	$ccount=count($cjr);
	//取得忧化字段
	for($ci=0;$ci<$ccount-1;$ci++)
	{
		$cir=explode($field,$cjr[$ci]);
		$cifield=$cir[1];
		if($cifield=="title")
		{
			continue;
		}
		$updatefield.=",".$cifield."=''";
	}
	for($i=0;$i<count($id);$i++)
	{
		$a.="id='".$id[$i]."' or ";
	}
	//去掉最后一个 or
	$a=substr($a,0,strlen($a)-4);
	$sql=$empire->query("select * from {$dbtbpre}ecms_infotmp_".$cr[tbname]." where ".$a." and checked=0 order by id desc");
	$filetime=date("Y-m-d H:i:s");
	while($r=$empire->fetch($sql))
	{
		$ivalue="";
		$ifield="";
		$titlepicnoval=0;
		for($j=0;$j<$ccount-1;$j++)
		{
			$cjr1=explode($field,$cjr[$j]);
			$dofield=$cjr1[1];
			$var="zz_".$dofield;
			$var1="z_".$dofield;
			$var2="qz_".$dofield;
			$var3="save_".$dofield;
			$value=$r[$dofield];
			//自身链接
			if($dofield=="empireselfurl")
			{
				$value=$r['oldurl'];
			}
			//内容
			if($dofield=="newstext"&&($cr[copyimg]||$cr[copyflash]))
			{
				$GLOBALS['cjnewsurl']=$r[oldurl];
				$value=addslashes(CopyImg(stripSlashes($value),$cr[copyimg],$cr[copyflash],$cr[newsclassid],$cr[imgurl],$username,0,$r['id'],$cr['mark']));
			}
			//简介
			if($dofield=="smalltext")
			{
				if(empty($value))
				{
					$value=SubSmalltextVal($r[newstext],$cr[smalltextlen]);
				}
				else
				{
					$value=DoClearSmalltextVal($value);
				}
			}
			//图片集
			if($dofield=="morepic")
			{
				if($cr[$var3]==" checked")
				{
					$msavepic=1;
					$r['filepass']=$r['id'];
					$value=LoadInSaveMorepicFile($value,$msavepic,$cr[newsclassid],0,$r);
				}
			}
			//信息时间
			if($dofield=="newstime")
			{continue;}
			//图片标题
			if($dofield=="titlepic"&&$cr[zz_titlepicl])
			{
				$cr[$var]=$cr[zz_titlepicl];
				$cr[$var1]=$cr[z_titlepicl];
				$cr[$var2]=$cr[qz_titlepicl];
				$cr[$var3]=$cr[save_titlepicl];
			}
			if($dofield=="titlepic"&&empty($value))
			{
				$titlepicnoval=1;
			}
			//是否远程保存
			if($value&&!$cr[$var1]&&$cr[$var3]==" checked"&&$dofield!="morepic")
			{
				$tranr=DoTranUrl($value,$cr[newsclassid]);
				if($tranr[tran])
				{
					$tranr[filesize]=(int)$tranr[filesize];
					$tranr[type]=(int)$tranr[type];
					$r[id]=(int)$r[id];
					//记录数据库
					$usql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,onclick,fpath) values('$tranr[filename]',$tranr[filesize],'$username','$tranr[filepath]','$filetime',$cr[newsclassid],'[URL]".$tranr[filename]."',$tranr[type],0,$r[id],0,'$public_r[fpath]');");
					$value=$tranr[url];
				}
			}
			//内容
			if($dofield=="newstext")
			{
				//存放文本
				if(strstr($public_r['savetxtf'],",".$cr[tbname].".newstext,"))
				{
					//建立目录
					$thetxtfile=GetFileMd5();
					$truevalue=MkDirTxtFile(date("Y/md"),$thetxtfile);
					//写放文件
					EditTxtFieldText($truevalue,$value);
					$value=$truevalue;
				}
			}
			$ifield.=",".$dofield;
			$value=RepDyh($value);
			$ivalue.=",'".$value."'";
		}
		$r[keyboard]=RepDyh($r[keyboard]);
		if($r[newstime]=="0000-00-00 00:00:00")
		{$r[newstime]=$filetime;}
		//查看目录是否存在，不存在则建立
		$newspath=FormatPath($cr[newsclassid],"",0);
		//强制签发
		if($class_r[$cr[newsclassid]][docheckuser]&&$class_r[$cr[newsclassid]][checkuser])
		{
			$checkuser=",".$class_r[$cr[newsclassid]][checkuser].",";
			$checked=0;
			$isqf=1;
		}
		else
		{
			$checkuser="";
			$checked=$checked;
			$isqf=0;
		}
		//变量处理
		$newstempid=(int)$class_r[$cr[newsclassid]][newstempid];
		//取得返回关键字
		$keyid=GetKeyid($r[keyboard],$cr[newsclassid],0,$class_r[$cr[newsclassid]][link_num]);
		$isql=$empire->query("insert into {$dbtbpre}ecms_".$cr[tbname]."(classid,onclick,newspath,keyboard,keyid,userid,username,ztid,checked,istop,truetime,ismember,dokey,isgood,titlefont,titleurl,filename,filenameqz,fh,groupid,newstempid,plnum,firsttitle,isqf,userfen,totaldown,closepl,havehtml,lastdotime,haveaddfen,infopfen,infopfennum,votenum,newstime".$ifield.") values($cr[newsclassid],0,'$newspath','$r[keyboard]','$keyid',$r[userid],'$r[username]','$cr[newsztid]',$checked,0,$r[truetime],0,1,0,'$r[titlefont]','$r[titleurl]','$filename','$r[filenameqz]',0,0,".$newstempid.",0,0,'$isqf',0,0,0,0,'$r[truetime]',0,0,0,0,'$r[newstime]'".$ivalue.");");
		$id=$empire->lastid();
		//签发
		if($isqf==1)
		{
			$iqfsql=$empire->query("insert into {$dbtbpre}enewsqf(id,classid,checkuser,docheckuser,viewcheckuser,returncheck,notdocheckuser,checked) values('$id','$cr[newsclassid]','".addslashes($checkuser)."',',',',',0,',',0);");
		}
		//更新附件
		UpdateTheFile($id,$r['id']);
		//取第一张图片为标题图片
		$addtitlepic="";
		if($cr['getfirstpic']&&$titlepicnoval)
		{
			$firsttitlepic=GetFpicToTpic($cr[newsclassid],$id,$cr['getfirstpic'],$cr['getfirstspic'],$cr['getfirstspicw'],$cr['getfirstspich']);
			if($firsttitlepic)
			{
				$addtitlepic=",titlepic='".addslashes($firsttitlepic)."'";
			}
		}
		//文件命名
		$filename=ReturnInfoFilename($cr[newsclassid],$id,$r[filenameqz]);
        $usql=$empire->query("update {$dbtbpre}ecms_".$cr[tbname]." set filename='$filename'".$addtitlepic." where id='$id'");
	}
	//状态原记录
	if($cr['delloadinfo'])//删除
	{
		$del=$empire->query("delete from {$dbtbpre}ecms_infotmp_".$cr[tbname]." where ".$a);
	}
	else
	{
		$del=$empire->query("update {$dbtbpre}ecms_infotmp_".$cr[tbname]." set checked=1,keyboard=''".$updatefield." where ".$a);
	}
	//操作日志
	insert_dolog("classid=".$classid);
	printerror("CjLoadDbSuccess","CheckCj.php?classid=$classid&from=$_POST[from]");
}

//全部采集入库
function CjNewsIn_all($classid,$checked,$start,$userid,$username){
	global $class_r,$empire,$public_r,$dbtbpre,$fun_r;
	$checked=(int)$checked;
	$classid=(int)$classid;
	if(empty($classid))
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	//操作权限
	CheckLevel($userid,$username,$classid,"cj");
	if(empty($start))
	{$start=0;}
	$cr=$empire->fetch1("select * from {$dbtbpre}enewsinfoclass where classid='$classid'");
	//副表
	$cra=$empire->fetch1("select * from {$dbtbpre}ecms_infoclass_".$cr[tbname]." where classid='$classid'");
	//组合两数组
    $cr=TogTwoArray($cr,$cra);
	//导入gd处理文件
	if($cr['mark']||$cr['getfirstspic'])
	{
		@include("gd.php");
	}
	if(empty($cr[insertnum]))
	{$cr[insertnum]=10;}
	//取得采集字段
	$record="<!--record-->";
	$field="<!--field--->";
	$mr=$empire->fetch1("select cj from {$dbtbpre}enewsmod where mid='".$class_r[$cr[newsclassid]][modid]."'");
	$cjr=explode($record,$mr[cj]);
	$ccount=count($cjr);
	$sql=$empire->query("select * from {$dbtbpre}ecms_infotmp_".$cr[tbname]." where classid='$classid' and checked=0 and id>$start order by id limit ".$cr[insertnum]);
	$filetime=date("Y-m-d H:i:s");
	$b=0;
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$newstart=$r[id];
		$ivalue="";
		$ifield="";
		$titlepicnoval=0;
		for($j=0;$j<$ccount-1;$j++)
		{
			$cjr1=explode($field,$cjr[$j]);
			$dofield=$cjr1[1];
			$var="zz_".$dofield;
			$var1="z_".$dofield;
			$var2="qz_".$dofield;
			$var3="save_".$dofield;
			$value=$r[$dofield];
			//自身链接
			if($dofield=="empireselfurl")
			{
				$value=$r['oldurl'];
			}
			//内容
			if($dofield=="newstext"&&($cr[copyimg]||$cr[copyflash]))
			{
				$GLOBALS['cjnewsurl']=$r[oldurl];
				$value=addslashes(CopyImg(stripSlashes($value),$cr[copyimg],$cr[copyflash],$cr[newsclassid],$cr[imgurl],$username,0,$r['id'],$cr['mark']));
			}
			//简介
			if($dofield=="smalltext")
			{
				if(empty($value))
				{
					$value=SubSmalltextVal($r[newstext],$cr[smalltextlen]);
				}
				else
				{
					$value=DoClearSmalltextVal($value);
				}
			}
			//图片集
			if($dofield=="morepic")
			{
				if($cr[$var3]==" checked")
				{
					$msavepic=1;
					$r['filepass']=$r['id'];
					$value=LoadInSaveMorepicFile($value,$msavepic,$cr[newsclassid],0,$r);
				}
			}
			//时间
			if($dofield=="newstime")
			{continue;}
			//图片标题
			if($dofield=="titlepic"&&$cr[zz_titlepicl])
			{
				$cr[$var]=$cr[zz_titlepicl];
				$cr[$var1]=$cr[z_titlepicl];
				$cr[$var2]=$cr[qz_titlepicl];
				$cr[$var3]=$cr[save_titlepicl];
			}
			if($dofield=="titlepic"&&empty($value))
			{
				$titlepicnoval=1;
			}
			//是否远程保存
			if($value&&!$cr[$var1]&&$cr[$var3]==" checked"&&$dofield!="morepic")
			{
				$tranr=DoTranUrl($value,$cr[newsclassid]);
				if($tranr[tran])
				{
					$tranr[filesize]=(int)$tranr[filesize];
					$tranr[type]=(int)$tranr[type];
					$r[id]=(int)$r[id];
					//记录数据库
					$usql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,onclick,fpath) values('$tranr[filename]',$tranr[filesize],'$username','$tranr[filepath]','$filetime',$cr[newsclassid],'[URL]".$tranr[filename]."',$tranr[type],0,$r[id],0,'$public_r[fpath]');");
					$value=$tranr[url];
				}
			}
			//内容
			if($dofield=="newstext")
			{
				//存放文本
				if(strstr($public_r['savetxtf'],",".$cr[tbname].".newstext,"))
				{
					//建立目录
					$thetxtfile=GetFileMd5();
					$truevalue=MkDirTxtFile(date("Y/md"),$thetxtfile);
					//写放文件
					EditTxtFieldText($truevalue,$value);
					$value=$truevalue;
				}
			}
			$ifield.=",".$dofield;
			$value=RepDyh($value);
			$ivalue.=",'".$value."'";
		}
		$r[keyboard]=RepDyh($r[keyboard]);
		if($r[newstime]=="0000-00-00 00:00:00")
		   {$r[newstime]=$filetime;}
		//查看目录是否存在，不存在则建立
		$newspath=FormatPath($cr[newsclassid],"",0);
		//强制签发
		if($class_r[$cr[newsclassid]][docheckuser]&&$class_r[$cr[newsclassid]][checkuser])
		{
			$checkuser=",".$class_r[$cr[newsclassid]][checkuser].",";
			$checked=0;
		}
		else
		{
			$checkuser="";
			$checked=$checked;
		}
		//变量处理
		$newstempid=(int)$class_r[$cr[newsclassid]][newstempid];
		//返回关键字
		$keyid=GetKeyid($r[keyboard],$cr[newsclassid],0,$class_r[$cr[newsclassid]][link_num]);
		$isql=$empire->query("insert into {$dbtbpre}ecms_".$cr[tbname]."(classid,onclick,newspath,keyboard,keyid,userid,username,ztid,checked,istop,truetime,ismember,dokey,isgood,titlefont,titleurl,filename,filenameqz,fh,groupid,newstempid,plnum,firsttitle,isqf,userfen,totaldown,closepl,havehtml,lastdotime,haveaddfen,infopfen,infopfennum,votenum,newstime".$ifield.") values($cr[newsclassid],0,'$newspath','$r[keyboard]','$keyid',$r[userid],'$r[username]','$cr[newsztid]',$checked,0,$r[truetime],0,1,0,'$r[titlefont]','$r[titleurl]','$filename','$r[filenameqz]',0,0,".$newstempid.",0,0,'$isqf',0,0,0,0,'$r[truetime]',0,0,0,0,'$r[newstime]'".$ivalue.");");
		$id=$empire->lastid();
		//签发
		if($isqf==1)
		{
			$iqfsql=$empire->query("insert into {$dbtbpre}enewsqf(id,classid,checkuser,docheckuser,viewcheckuser,returncheck,notdocheckuser,checked) values('$id','$cr[newsclassid]','".addslashes($checkuser)."',',',',',0,',',0);");
		}
		//更新附件
		UpdateTheFile($id,$r['id']);
		//取第一张图片为标题图片
		$addtitlepic="";
		if($cr['getfirstpic']&&$titlepicnoval)
		{
			$firsttitlepic=GetFpicToTpic($cr[newsclassid],$id,$cr['getfirstpic'],$cr['getfirstspic'],$cr['getfirstspicw'],$cr['getfirstspich']);
			if($firsttitlepic)
			{
				$addtitlepic=",titlepic='".addslashes($firsttitlepic)."'";
			}
		}
		//文件命名
		$filename=ReturnInfoFilename($cr[newsclassid],$id,$r[filenameqz]);
        $usql=$empire->query("update {$dbtbpre}ecms_".$cr[tbname]." set filename='$filename'".$addtitlepic." where id='$id'");
	}
	$fm=$_GET['fm'];
	//全部入库完毕
	if(empty($b))
	{
		//取得忧化字段
		for($ci=0;$ci<$ccount-1;$ci++)
	    {
			$cir=explode($field,$cjr[$ci]);
			$cifield=$cir[1];
			if($cifield=="title")
			{
				continue;
			}
			$updatefield.=",".$cifield."=''";
		}
		//状态原记录
		if($cr['delloadinfo'])//删除
		{
			$del=$empire->query("delete from {$dbtbpre}ecms_infotmp_".$cr[tbname]." where classid='$classid'");
		}
		else
		{
			$del=$empire->query("update {$dbtbpre}ecms_infotmp_".$cr[tbname]." set checked=1,keyboard=''".$updatefield." where classid='$classid'");
		}
		if($fm)
		{
			echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><body topmargin=0><font color=red>".$cr[classname]."  ".$fun_r['CjLoadInInfosSuccess']."</font>,  <input type=button name=button value='".$fun_r['OnlickLoadInCj']."' onclick=\"window.open('CheckCj.php?classid=$classid&from=$_GET[from]');\"></body>";
			exit();
		}
		else
		{
			printerror("CjLoadDbSuccess","CheckCj.php?classid=$classid&from=$_GET[from]");
		}
	}
	echo "<b>$cr[classname]</b>&nbsp;&nbsp;".$fun_r['OneCjLoadDbSuccess']."(ID:<font color=red><b>".$newstart."</b></font>)<script>self.location.href='enews.php?enews=CjNewsIn_all&checked=$checked&classid=$classid&start=$newstart&fm=$fm&from=$_GET[from]';</script>";
	exit();
}

//增加标签
function AddBq($add,$bqsay,$userid,$username){
	global $empire,$dbtbpre;
	if(!$add[bqname]||!$add[funname]||!$add[bq])
	{printerror("EmptyBqname","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"bq");
	//标签重复
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsbq where bq='$add[bq]' limit 1");
	if($num)
	{printerror("ReBq","history.go(-1)");}
	//函数是否存在
	if(!function_exists($add[funname]))
	{
		printerror("NotFun","history.go(-1)");
    }
	$classid=(int)$add['classid'];
	$add[isclose]=(int)$add[isclose];
	$bqsay=RepPhpAspJspcodeText($bqsay);
	$sql=$empire->query("insert into {$dbtbpre}enewsbq(bqname,bqsay,funname,bq,issys,bqgs,isclose,classid) values('".$add[bqname]."','".addslashes($bqsay)."','$add[funname]','$add[bq]',0,'".addslashes($add[bqgs])."',$add[isclose],$classid);");
	$bqid=$empire->lastid();
	if($sql)
	{
		//操作日志
		insert_dolog("bqid=".$bqid."<br>bqname=".$add[bqname]);
		printerror("AddBqSuccess","template/AddBq.php?enews=AddBq");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改标签
function EditBq($add,$bqsay,$userid,$username){
	global $empire,$dbtbpre;
	$add[bqid]=(int)$add[bqid];
	if(!$add[bqname]||!$add[funname]||!$add[bq]||!$add[bqid])
	{printerror("EmptyBqname","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"bq");
	//标签重复
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsbq where bq='$add[bq]' and bqid<>'$add[bqid]' limit 1");
	if($num)
	{printerror("ReBq","history.go(-1)");}
	//函数是否存在
	if(!function_exists($add[funname]))
	{
		printerror("NotFun","history.go(-1)");
    }
	$bqsay=RepPhpAspJspcodeText($bqsay);
	$classid=(int)$add['classid'];
	$add[isclose]=(int)$add[isclose];
	$sql=$empire->query("update {$dbtbpre}enewsbq set bqname='$add[bqname]',bqsay='".addslashes($bqsay)."',funname='$add[funname]',bq='$add[bq]',bqgs='".addslashes($add[bqgs])."',isclose=$add[isclose],classid=$classid where bqid='$add[bqid]'");
	if($sql)
	{
		//操作日志
	    insert_dolog("bqid=".$add[bqid]."<br>bqname=".$add[bqname]);
		printerror("EditBqSuccess","template/ListBq.php?classid=$add[cid]");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//删除标签
function DelBq($bqid,$cid,$userid,$username){
	global $empire,$dbtbpre;
	$bqid=(int)$bqid;
	if(empty($bqid))
	{printerror("NotDelBqid","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"bq");
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsbq where bqid='$bqid' and issys=0");
	if(empty($num))
	{printerror("NotDelSysBq","history.go(-1)");}
	$r=$empire->fetch1("select bqname from {$dbtbpre}enewsbq where bqid='$bqid'");
	$sql=$empire->query("delete from {$dbtbpre}enewsbq where bqid='$bqid'");
	if($sql)
	{
		//操作日志
	    insert_dolog("bqid=".$bqid."<br>bqname=".$r[bqname]);
		printerror("DelBqSuccess","template/ListBq.php?classid=$cid");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//批量转移信息
function MoveClassNews($add,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	$add[classid]=(int)$add[classid];
	$add[toclassid]=(int)$add[toclassid];
	if(empty($add[classid])||empty($add[toclassid]))
	{
		printerror("EmptyMovetoClassid","history.go(-1)");
	}
	if($class_r[$add[classid]][modid]<>$class_r[$add[toclassid]][modid])
	{
		printerror("DefModid","history.go(-1)");
    }
	//验证权限
	CheckLevel($userid,$username,$classid,"movenews");
	//终极栏目
	if(!$class_r[$add[classid]][islast]||!$class_r[$add[toclassid]][islast])
	{
		printerror("MovetoClassidMustLastid","history.go(-1)");
	}
	if($add[classid]==$add[toclassid])
	{
		printerror("MoveClassidsame","history.go(-1)");
	}
	$sql=$empire->query("update {$dbtbpre}ecms_".$class_r[$add[toclassid]][tbname]." set classid=$add[toclassid] where classid='$add[classid]'");
	//评论转换
	$uplsql=$empire->query("update {$dbtbpre}enewspl set classid=$add[toclassid] where classid='$add[classid]'");
	//签发转换
	$uqfsql=$empire->query("update {$dbtbpre}enewsqf set classid=$add[toclassid] where classid='$add[classid]'");
	//投票
	$uvotesql=$empire->query("update {$dbtbpre}enewsinfovote set classid=$add[toclassid] where classid='$add[classid]'");
	//返回自定义字段
	$ret_r=ReturnAddF($r,$class_r[$add[toclassid]][modid],$userid,$username,2,2,0);
	//生成信息列表
	ListHtml($add[toclassid],$ret_r,0);
	//移动数据
	$opath="../../".$class_r[$add[classid]][classpath];
    DelPath($opath);//删除旧的栏目目录
	$mk=DoMkdir($opath);
	if($sql)
	{
		//操作日志
		insert_dolog("classid=".$add[classid]."&nbsp;(".$class_r[$add[classid]][classname].")<br>toclassid=".$add[toclassid]."(".$class_r[$add[toclassid]][classname].")");
		printerror("MoveClassNewsSuccess","MoveClassNews.php");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改栏目顺序
function EditClassOrder($classid,$myorder,$userid,$username){
	global $empire,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"class");
	for($i=0;$i<count($classid);$i++)
	{
		$newmyorder=(int)$myorder[$i];
		$sql=$empire->query("update {$dbtbpre}enewsclass set myorder=$newmyorder where classid='$classid[$i]'");
    }
	//删除缓存
	DelListEnews();
	//操作日志
	insert_dolog("");
	printerror("EditClassOrderSuccess",$_SERVER['HTTP_REFERER']);
}

//修改搜索页面
function EditSearchTemp($tempname,$temptext,$userid,$username){
	global $empire,$dbtbpre,$public_r;
	if(empty($temptext)||empty($tempname))
	{printerror("EmptySearchTemp","history.go(-1)");}
	//操作权限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$tempname=RepPostVar($tempname);
	if($tempname=="searchtemp")//搜索表单模板
	{
		$f="searchtemp";
		$tname="searchformtemp";
	}
	elseif($tempname=="searchjstemp")//搜索JS模板（横向)
	{
		$temptext=str_replace("\r\n","",$temptext);
		$f="searchjstemp";
		$tname="searchformjs";
	}
	else//搜索JS模板（纵向)
	{
		$temptext=str_replace("\r\n","",$temptext);
		$f="searchjstemp1";
		$tname="searchformjs1";
    }
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set ".$f."='".addslashes($temptext)."'");
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		GetSearch();
	}
	if($sql)
	{
		//操作日志
		insert_dolog("temp=$f&gid=$gid");
		printerror("EditSearchTempSuccess","template/EditPublicTemp.php?tname=$tname&gid=$gid#$tempname");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改相关链接模板
function EditOtherLinkTemp($tempname,$temptext,$userid,$username){
	global $empire,$dbtbpre;
	if(empty($temptext)||empty($tempname))
	{printerror("EmptyOtherLinkTemp","history.go(-1)");}
	//操作权限
	CheckLevel($userid,$username,$classid,"template");
	$tempname=RepPostVar($tempname);
	$temptext=RepPhpAspJspcode($temptext);
	$f="otherlinktemp";
	$tname="otherlinktemp";
	$otherlinktempsub=(int)$_POST['otherlinktempsub'];
	$otherlinktempdate=$_POST['otherlinktempdate'];
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set ".$f."='".addslashes($temptext)."',otherlinktempsub=$otherlinktempsub,otherlinktempdate='".addslashes($otherlinktempdate)."'");
	if($sql)
	{
		//操作日志
		insert_dolog("temp=$f&gid=$gid");
		printerror("EditOtherLinkTempSuccess","template/EditPublicTemp.php?tname=$tname&gid=$gid#$tempname");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改打印模板
function EditPrintTemp($tempname,$temptext,$userid,$username){
	global $empire,$dbtbpre,$public_r;
	if(empty($temptext)||empty($tempname))
	{printerror("EmptyPrintTemp","history.go(-1)");}
	//操作权限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$tempname=RepPostVar($tempname);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set ".$tempname."='".addslashes($temptext)."'");
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		if($tempname=="downsofttemp"||$tempname=="onlinemovietemp"||$tempname=="listpagetemp")
		{
			GetConfig();
		}
		else
		{
			GetPrintPage();
		}
	}
	if($sql)
	{
		//操作日志
		insert_dolog("temp=$tempname&gid=$gid");
		printerror("EditDownTempSuccess","template/EditPublicTemp.php?tname=$tempname&gid=$gid#$tempname");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//删除目录文件
function DelPathFile($filename,$userid,$username){
	global $empire,$dbtbpre;
	//操作权限
	CheckLevel($userid,$username,$classid,"file");
	$count=count($filename);
	if(empty($count))
	{
		printerror("NotFileid","history.go(-1)");
	}
	//基目录
	$basepath="../../d/file";
	for($i=0;$i<$count;$i++)
	{
		if(strstr($filename[$i],".."))
		{
			continue;
	    }
		DelFiletext($basepath."/".$filename[$i]);
		$dfile=ReturnPathFile($filename[$i]);
		$sql=$empire->query("delete from {$dbtbpre}enewsfile where filename='$dfile'");
    }
	//操作日志
	insert_dolog("");
	printerror("DelFileSuccess",$_SERVER['HTTP_REFERER']);
}

//增加自定义页面
function AddUserpage($add,$userid,$username){
	global $empire,$dbtbpre;
	//操作权限
	CheckLevel($userid,$username,$classid,"userpage");
	$classid=(int)$add[classid];
	$title=$add['title'];
	$path=$add['path'];
	$pagetext=$add['pagetext'];
	if(empty($title)||empty($path))
	{
		printerror("EmptyUserpagePath","history.go(-1)");
    }
	$pagetext=addslashes(RepPhpAspJspcode($pagetext));
	$pagetitle=addslashes(RepPhpAspJspcode($add[pagetitle]));
	$pagekeywords=addslashes(RepPhpAspJspcode($add[pagekeywords]));
	$pagedescription=addslashes(RepPhpAspJspcode($add[pagedescription]));
	$sql=$empire->query("insert into {$dbtbpre}enewspage(title,path,pagetext,classid,pagetitle,pagekeywords,pagedescription) values('$title','$path','$pagetext',$classid,'$pagetitle','$pagekeywords','$pagedescription');");
	$id=$empire->lastid();
	ReUserpage($id,$pagetext,$path,$title,$pagetitle,$pagekeywords,$pagedescription);
	if($sql)
	{
		//操作日志
	    insert_dolog("id=$id&title=$title");
		printerror("AddUserpageSuccess","template/AddPage.php?enews=AddUserpage");
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//修改自定义页面
function EditUserpage($add,$userid,$username){
	global $empire,$dbtbpre;
	//操作权限
	CheckLevel($userid,$username,$classid,"userpage");
	$id=(int)$add['id'];
	$classid=(int)$add[classid];
	$title=$add['title'];
	$path=$add['path'];
	$pagetext=$add['pagetext'];
	if(!$id||empty($title)||empty($path))
	{
		printerror("EmptyUserpagePath","history.go(-1)");
    }
	//改变地址
	if($add['oldpath']<>$path)
	{
		DelFiletext($add['oldpath']);
	}
	$pagetext=addslashes(RepPhpAspJspcode($pagetext));
	$pagetitle=addslashes(RepPhpAspJspcode($add[pagetitle]));
	$pagekeywords=addslashes(RepPhpAspJspcode($add[pagekeywords]));
	$pagedescription=addslashes(RepPhpAspJspcode($add[pagedescription]));
	$sql=$empire->query("update {$dbtbpre}enewspage set title='$title',path='$path',pagetext='$pagetext',classid=$classid,pagetitle='$pagetitle',pagekeywords='$pagekeywords',pagedescription='$pagedescription' where id='$id'");
	ReUserpage($id,$pagetext,$path,$title,$pagetitle,$pagekeywords,$pagedescription);
	if($sql)
	{
		//操作日志
	    insert_dolog("id=$id&title=$title");
		printerror("EditUserpageSuccess","template/ListPage.php?classid=$add[cid]");
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//删除自定义页面
function DelUserpage($id,$cid,$userid,$username){
	global $empire,$dbtbpre;
	//操作权限
	CheckLevel($userid,$username,$classid,"userpage");
	$id=(int)$id;
	if(empty($id))
	{
		printerror("EmptyDelUserpageid","history.go(-1)");
    }
	$r=$empire->fetch1("select title,id,path from {$dbtbpre}enewspage where id='$id'");
	if(empty($r['id']))
	{
		printerror("NotDelUserpageid","history.go(-1)");
	}
	$sql=$empire->query("delete from {$dbtbpre}enewspage where id='$id'");
	DelFiletext($r['path']);
	if($sql)
	{
		//操作日志
	    insert_dolog("id=$id&title=$r[title]");
		printerror("DelUserpageSuccess","template/ListPage.php?classid=$cid");
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//批量推荐/头条信息
function GoodInfo_all($classid,$id,$isgood,$doing=0,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	$classid=(int)$classid;
	if(empty($classid))
	{printerror("ErrorUrl","history.go(-1)");}
	//验证权限
	$doselfinfo=CheckLevel($userid,$username,$classid,"news");
	//编辑权限
	if(!$doselfinfo['doeditinfo'])
	{
		printerror("NotEditInfoLevel","history.go(-1)");
	}
	$isgood=(int)$isgood;
	$doing=(int)$doing;
	if($doing==0)//推荐
	{
		$mess="EmptyGoodInfoId";
		$domess="GoodInfoSuccess";
		$setf="isgood=$isgood";
	}
	else//头条
	{
		$mess="EmptyFirsttitleInfoId";
		$domess="FirsttitleInfoSuccess";
		$setf="firsttitle=$isgood";
	}
	$count=count($id);
	if(empty($count))
	{printerror($mess,"history.go(-1)");}
	for($i=0;$i<$count;$i++)
	{
		$add.="id='$id[$i]' or ";
    }
	$add=substr($add,0,strlen($add)-4);
	$sql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set ".$setf." where ".$add);
	if($sql)
	{
		//操作日志
		insert_dolog("classid=".$classid."<br>classname=".$class_r[$classid][classname]);
		printerror($domess,$_SERVER['HTTP_REFERER']);
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//转至专题
function DoZtNews_all($classid,$id,$ztid,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	$classid=(int)$classid;
	if(empty($classid))
	{printerror("ErrorUrl","history.go(-1)");}
	//验证权限
	$doselfinfo=CheckLevel($userid,$username,$classid,"news");
	//编辑权限
	if(!$doselfinfo['doeditinfo'])
	{
		printerror("NotEditInfoLevel","history.go(-1)");
	}
	$ztid=(int)$ztid;
	if(!$ztid)
	{
		printerror("EmptyDoZtid","history.go(-1)");
	}
	$count=count($id);
	if(empty($count))
	{printerror("EmptyDoZtInfoId","history.go(-1)");}
	for($i=0;$i<$count;$i++)
	{
		$add.="id='$id[$i]' or ";
    }
	$add=substr($add,0,strlen($add)-4);
	$repztid="|".$ztid."|";
	$conztid=$ztid."|";
	//将空转换为|
	$usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set ztid='|' where (".$add.") and ztid=''");
	//设置专题
	$sql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set ztid=CONCAT(REPLACE(ztid,'".$repztid."','|'),'".$conztid."') where ".$add);
	if($sql)
	{
		//操作日志
		insert_dolog("classid=".$classid."<br>classname=".$class_r[$classid][classname]);
		printerror("DoZtInfoSuccess",$_SERVER['HTTP_REFERER']);
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//本栏目信息全部审核
function SetAllCheckInfo($bclassid,$classid,$userid,$username){
	global $empire,$dbtbpre,$class_r;
	$classid=(int)$classid;
	if(empty($classid))
	{printerror("ErrorUrl","history.go(-1)");}
	//验证权限
	$doselfinfo=CheckLevel($userid,$username,$classid,"news");
	//编辑权限
	if(!$doselfinfo['doeditinfo'])
	{
		printerror("NotEditInfoLevel","history.go(-1)");
	}
	//只能操作自己的信息
	if($doselfinfo['doselfinfo'])
	{
		$a.=" and userid='$userid' and ismember=0";
	}
	$sql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set checked=1 where classid=$classid and isqf=0".$a);
	if($sql)
	{
		//操作日志
		insert_dolog("classid=".$classid."<br>classname=".$class_r[$classid][classname]);
		printerror("CheckNewsSuccess",$_SERVER['HTTP_REFERER']);
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//生成单信息
function ReSingleInfo($userid,$username){
	global $empire,$public_r,$class_r,$dbtbpre;
	if($_GET['classid'])
	{
		$classid=(int)$_GET['classid'];
		$id=$_GET['id'];
	}
	else
	{
		$classid=(int)$_POST['classid'];
		$id=$_POST['id'];
	}
	if(empty($classid))
	{
		printerror('ErrorUrl','history.go(-1)');
	}
	$count=count($id);
	if(empty($count))
	{
		printerror("NotReInfoid","history.go(-1)");
	}
	for($i=0;$i<$count;$i++)
	{
		$add.="id='$id[$i]' or ";
    }
	$add=substr($add,0,strlen($add)-4);
	$sql=$empire->query("select * from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where ".$add);
	while($r=$empire->fetch($sql))
	{
		$ret_r=ReturnAddF($r,$class_r[$r[classid]][modid],$userid,$username,2,1,0);//返回自定义字段
		GetHtml($r,$ret_r);//生成信息文件
	}
	//操作日志
	insert_dolog("classid=".$classid);
	printerror("ReSingleInfoSuccess",$_SERVER['HTTP_REFERER']);
}
?>